Re: [PHP] PHP & Memory Allocation (checked via TOP)



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
.



Relevant Pages

  • Re: Framework 2.0 array redim unsatisfactory performance
    ... implementation details of Redim, Redim Preserve, and List. ... significantly higher object allocated overhead then List. ... ReDim simply allocates a new ... but I do not even attempt to test its memory ...
    (microsoft.public.dotnet.languages.vb)
  • PHP & Memory Allocation (checked via TOP)
    ... 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 ...
    (php.general)
  • Re: CE6.0 Driver Pointer Marshalling - passing pointers out only?
    ... This is an array of pointers to buffers that get set up ... the driver allocates the buffers (via an internal allocation ... routine from its own block of reserved memory). ... So I can map ...
    (microsoft.public.windowsce.platbuilder)
  • Re: CE6.0 Driver Pointer Marshalling - passing pointers out only?
    ... I've got a pretty complex driver I'm porting up at the moment ... This is an array of pointers to buffers that get set up ... the driver allocates the buffers (via an internal allocation ... routine from its own block of reserved memory). ...
    (microsoft.public.windowsce.platbuilder)
  • Re : Re : memory allocation and freeing memory
    ... This means that the caller ... >> never frees memory, and the callee always frees all its ... then the caller allocates it and pass it ... > void ExprDestroy(Expr *expr) { ...
    (comp.lang.c)