Re: Pointers For Newbies, Reminders For Oldies
| From: | Nathan Rixham | Date: | Thu, 28 Jan 2010 13:42:53 +0000 |
| Subject: | Re: Pointers For Newbies, Reminders For Oldies | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-301606@lists.php.net to get a copy of this message | ||
Ford, Mike wrote:
>> -----Original Message-----
>> From: Rene Veerman [mailto:rene7705@gmail.com]
>> Sent: 27 January 2010 22:46
>>
>> And if your script needs to pass large (> 5Mb) arrays around to
>> functions, be sure to use passing-by-reference; failing to do so can
>> double your memory requirements,
>> possibly hitting the ini_set('memory_lmit', ??)
>
> Have you benchmarked this? PHP's copy-on-change philosophy means there shouldn't be
> much difference in memory terms -- so unless you actually expect to change the array's
> contents, you should pass by value.
>
> As proof, I constructed this little test:
>
> function test($arg, $base_mem)
> {
> echo "Additional inside func = ", memory_get_usage()-$base_mem, "<br
> />\n";
> }
>
try changing this to access the array in some way such as:
function test($arg, $base_mem)
{
foreach( $arg as $index => $value ) {
}
echo "Additional= ", memory_get_usage()-$base_mem, "\n";
}
After array creation = 52696
Additional = 101152
Final = 117200
vs: function test(&$arg, $base_mem)
After array creation = 52696
Additional = 53104
Final = 101696
there's the double memory usage