Why does a simple PHP unset() memory test utilize twice the amount of memory in PHP 5.3? -
i testing out whether unset() affects memory while script running, see if unset() or other known method, $var=null more efficient. unset() did affect memory, since tested out on 2 different virtualhosts, wondered why 1 take more or less twice amount of memory same script? i'm guessing answer simple, escapes me @ moment. script below:
<?php $init=memory_get_usage(); $test=array(); for($i=0;$i<=100000;$i++){ $test[$i]=rand(0,10000000); } echo 'memory change: '.((memory_get_usage()-$init)/1024/1024).'mb<br/>'; for($i=0;$i<=100000;$i++){ unset($test[$i]); } echo 'memory change: '.((memory_get_usage()-$init)/1024/1024).'mb<br/>'; //output on php 3.2.5 virtualhost: //memory change: 6.98558807373mb //memory change: 0.500259399414mb //output on php 5.3.5 virtualhost //memory change: 13.970664978mb //memory change: 1.00063323975mb ?>
thanks!
php 3.2.5? that's old doesn't reach stone age. php's guts underwent total re-write zend engine, though language stayed relatively same, you're comparing 2 different environments.
but in case version number typo, possibly it's 32bit v.s. 64bit host, doubles size of ints , account purported 2x difference.
Comments
Post a Comment