Re: PHP & Memory Allocation (checked via TOP)

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

 



Cabbar Duzayak wrote:
Hi,

I have written a simple test program to see how php allocates memory.
Test code allocates ~10 Meg of RAM in an array within a loop till it
runs out of memory as:

 $str = rand(65, 95) . rand(65, 95) . rand(65, 95) . rand(65, 95) .
rand(65, 95);
 $aa[] = str_repeat($str, 2000000);

What I don't understand here is, for every 10 Meg memory it allocates,
mem usage goes up about 19 Megs when I look at this via top.
Just looked over this really quickly, so I might have missed something, but it seems to me that you're allocating almost 20 megs...

your $str is 10 bytes long (plus terminator and PHP overhead, whatever that turns out to be...), and you're repeating it two million times. 10 bytes times 2 million is 20 million bytes. 20 000 000 divided by (1024*1024) is 19.07 -> it seems to me that you're allocating 19.07 megs, and top is showing you that it's allocating 19 megs...? Seems about right.

jon

--
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