Hi folks. I have a question about the PHP runtime that I hope is appropriate
for this list. (If not, please thwap me gently; I bruise easily.)
I know PHP does copy-on-write. However, how "deeply" does it copy when
dealing with nested arrays?
This is probably easiest to explain with an exampl
It does the whole of $b. It has to, because when you change 'baz', a reference in
'bar' needs to change to point to the newly copied 'baz', so 'bar' is
written...and likewise 'foo' is written.
Ben.
On 19/01/11 5:45 PM, Larry Garfield wrote:
Hi folks. I have a question about the PHP runtime
That's what I was afraid of. So it does copy the entire array. Crap. :-)
Am I correct that each level in the array represents its own ZVal, with the
additional memory overhead a ZVal has (however many bytes that is)?
That is, the array below would have $a, foo, bar, baz, bob, narf, poink,
poi
Yep. PHP does clock up memory very quickly for big arrays, objects with lots of
members and/or lots of small objects with large overheads. There are a LOT of
zvals and zobjects and things around the place, and their overhead isn't all that
small.
Of course, if you go to the trouble to construc
Using references does not speed up PHP. It does that already
internally, if I'm not mistaken. The point of my post was that
assigning values to tree arrays are in general faster than a full
array copy.
Hannes
On 19 January 2011 08:36, Ben Schmidt wrote:
> Yep. PHP does clock up memory very quick
What about objects?
class Foo {
public $foo;
}
function test($o) {
$o->foo->foo->foo = 2;
}
$bar = new Foo;
$bar->foo = new Foo;
$bar->foo->foo = new Foo;
test( $bar );
---
Also... is it better to pass an object as a parameter rather than many
values?
function withValues($anInteger, $
On Wed, 19 Jan 2011 14:23:49 -, Martin Scotta
wrote:
What about objects?
With objects less copying occurs because the object value (zval) data is
actually just a pointer and an id that for most purposes works as a
pointer.
However, it should be said that while a copy of an array f
So it sounds like the general answer is that if you pass a complex array
to a function by value and mess with it, data is duplicated for every
item you modify and its direct ancestors up to the root variable but not
for the rest of the tree.
For objects, because of their "pass by handle"-type
On 19 January 2011 20:05, la...@garfieldtech.com wrote:
> So it sounds like the general answer is that if you pass a complex array to
> a function by value and mess with it, data is duplicated for every item you
> modify and its direct ancestors up to the root variable but not for the rest
> of th
On 20/01/11 6:05 AM, la...@garfieldtech.com wrote:
So it sounds like the general answer is that if you pass a complex array to a
function by value and mess with it, data is duplicated for every item you modify
and its direct ancestors up to the root variable but not for the rest of the
tree.
Fo
On Wednesday, January 19, 2011 4:45:14 pm Ben Schmidt wrote:
> > Related: What is the overhead of a ZVal? I'm assuming it's a fixed
> > number of bytes.
>
> It seems not, though a zval has a fixed size. What that size is will
> depend on the compiler and architecture of the system being used, or
11 matches
Mail list logo