Jump to content

[SOLVED] Bad things come to mind when thinking about it.


pkedpker

Recommended Posts

my question is there any overhead doing just function calls like this

 

<?php //color
$fh = fopen("data/test.txt", 'r'); 
$data = fread($fh, filesize("data/test.txt")); 
fclose($fh); 

 

compared to

 

<?php //color
$data = loadData("test.txt");

function loadData($filename) {
$fh = fopen("data/$filename", 'r'); 
$data = fread($fh, filesize("data/$filename")); 
fclose($fh); 
return $data;
}

 

since I remember returning something very huge.. like 2GB is kinda bad because it would do a copy of all bytes losing time.. unless its a shared pointer is it?

 

I just want to know if there is any speed loss?.. other then calling functions.. should i rebuilt this function algorithm in every piece of coding i need to load something just so i don't have to return it?

 

Assuming PHP is intelligent enough to return a pointer to the memory allocated for $data it should use about the same amount of memory.

 

Otherwise though, it will use double.

 

 

I bet that PHP will return a pointer to the previously allocated memory though.

 

 

 

Not sure though.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.