[pmwiki-users] Request input on soon-coming FAST Data release

Patrick R. Michaud pmichaud at pobox.com
Wed Oct 4 17:48:43 CDT 2006


On Wed, Oct 04, 2006 at 03:36:59PM -0700, Martin Fick wrote:
> --- Joachim Durchholz <jo at durchholz.org> wrote:
> 
> > Patrick R. Michaud schrieb:
> > > Could someone perhaps find a more definitive
> > answer for this
> > > question?  My task list is a bit full at the
> > moment... :-|
> > 
> > A quick check whether arrays are copied on write
> > would be a loop with 
> > something like this:
> >    $a = array ($a, $a);
> > This creates two copies of $a on every step; if
> > arrays are copied, 
> > memory usage should double at each step and hit the
> > 8MB RAM limit very 
> > quickly, if they are copied on write, it should not
> > be able to fill memory.
> 
> Usage will double -> not the question you are trying
> to answer.  You are trying to find out if when passed
> by reference (i.e not copied explictly like this
> example does) are they still somehow copied?  

No, this still isn't the question.  The real question
is:  if an array is passed to a function by *value*,
is it copied at the point of the function call or only
at the point where it's modified?

The real test is:  how long does it take for the following
code to fail?

    function foo($a, $n) {
      $n++;
      print "Iteration $n\n";
      foo($a, $n);
    }

    ## create a 100,000 element array
    $a = array_pad(array(), 100000, 1);

    ## call the foo function above
    foo($a, 0);


If PHP is copy-on-write for array parameters, then we should be 
able to do a lot of recursions of the foo() function before 
running out of memory.  If it makes a copy of the array for
each call, then we should run out of memory fairly quickly.

I'd test this on my system, but unfortunately my PHP installs
don't have memory limits enabled so I can't really find the
"out of memory" part.  (And it has always *really* bugged
me that the function to determine PHP's memory usage has to be
specifically compiled into PHP -- most stock PHP's don't have it
enabled.)

Pm




More information about the pmwiki-users mailing list