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?

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.