PHP & Memory Allocation (checked via TOP)

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

 



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.
Basically, it allocates from physical memory in the beginning, starts
using swap when it is out of RES/Physical memory, which makes me
assume that garbage collection should kick in for temporary string
creations, and each new allocation increases the allocated memory size
by 19 Megs.

Any idea why this is happening, and why do you think memory allocation
is so expensive in PHP?

Thanks..


Results of TOP:

 PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
21843 apache    17   0 19292 5232 3832 S  0.0  0.5   0:00.04 php
21843 apache    16   0 38824  24m 3908 S  0.0  2.4   0:00.10 php
21843 apache    15   0 58356  43m 3912 S  0.0  4.3   0:00.17 php
21843 apache    16   0 77888  62m 3912 S  0.0  6.2   0:00.22 php
21843 apache    15   0 97420  81m 3912 S  0.0  8.1   0:00.29 php
21843 apache    15   0  114m 100m 3912 S  0.0  9.9   0:00.35 php


Results of free -m:

            total       used       free     shared    buffers     cached
Mem:          1011        138        872          0          2         58
Swap:         2008        388       1619

Mem:          1011        158        852          0          2         58
Swap:         2008        388       1619

Mem:          1011        177        833          0          2         58
Swap:         2008        388       1619

Mem:          1011        196        814          0          2         58
Swap:         2008        388       1619

Mem:          1011        216        795          0          2         58
Swap:         2008        388       1619

Mem:          1011        234        776          0          2         58
Swap:         2008        388       1619

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