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 at
> least on the ABI.

Ah, yes, of course.  Oh C...

*snip*

> The zvalue_value union will probably be 8 or 12 bytes, depending on the
> architecture. The whole struct will then probably be between 14 and 24
> bytes, depending on the architecture and structure alignment and so on.

*snip*

> You can figure out what you think the overhead is from that. For a
> string, arguably the whole structure is overhead, since the string is
> stored elsewhere via pointer. Likewise for objects. For a double, the
> payload is 8 bytes, and stored in the zval, so there's less overhead. An
> integer, with a payload of 4 bytes, is somewhere in between.

Hm.  OK, so if I'm assuming a 64-bit architecture (most servers these days, 
I'd think) and just looking for a rough approximation, it sounds like 20 bytes 
per zval/variable is a not unreasonable estimation.  At least close enough for 
determining the memory overhead of a general algorithm.

Thanks again!

--Larry Garfield

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to