I keep hearing that PHP has overhead. For example a C++ int uses 4 Bytes on a 32 bit system but a PHP int uses more. What is this value?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I need more space than a comment to expand on mario’s findings so I’ll add an answer instead.
The size of a C
unionwill be the size of its largest member (possibly with extra bytes to satisfy alignment constraints). Forzvalue_value, that would be theobjwhich has the size of three pointers (not including the memory required for what those pointers point to):On a 32bit system, a
zend_objectwill take 24 bytes while on a 64bit system it will take 48 bytes. So, everyzvalue_valuewill take at least 24 or 48 bytes regardless of what data you store in it. There’s also the name of the variable which consumes more memory; compiled languages generally discard the names once the compiler is done and treat values as simple sequences of bytes (so adoubletakes eight bytes, achartakes one byte, etc…).With regards to your recent questions about PHP booleans, a simple boolean value will consume 24 or 48 bytes for the value, plus a few more bytes for the name, plus four or eight for the
zend_unit, plus four (or eight) for the twozend_uchars in this:The
zend_ucharmembers will chew up four (or eight) bytes due to alignment constraints, almost every CPU wants to access memory on natural address boundaries and that means that a single byte sized member of astructwill take up four bytes or eight bytes of memory (depending on the CPUs natural word size and alignment constraints). So, a boolean will take somewhere between 36 and 72 bytes of memory.