Re: Pointers For Newbies, Reminders For Oldies

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Ford, Mike wrote:
>> -----Original Message-----
>> From: Rene Veerman [mailto:rene7705@xxxxxxxxx]
>> 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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux