Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I don't have extensive knowledge of PHP internals, but the concept is that when you create a variable with an integer value, PHP internally allocates a structure (such structures are usually called <em>variants</em>) that is capable of holding any type of value in the language (which includes object types, functions, etc). This is bound to require more than a lowly 4 bytes.</p> <p>With that out of the way, the question that remains is why 72 (and not for example 42)? For an answer to this we 'd need to examine not only the C source (to see <em>exactly</em> what is allocated and what its memory footprint is) but also the implementation of <code>memory_get_usage</code> (to see how exactly it <em>counts</em> memory usage).</p> <p><strong>Update:</strong> I feel I need to stress the "how it counts memory usage" part more.</p> <p>It is entirely possible that the allocation of a new variable causes PHP's memory allocator to reserve a block of memory from the C heap substantially larger than what it needs to satisfy the variable allocation request (it can also decide to keep this memory future use even after you e.g. <code>unset</code> the variable).</p> <p>If <code>memory_get_usage</code> wants to count the whole memory block as "used", then you could even see a simple integer variable cause usage to go up by, say, 1K (if things were as simple as I have described so far, an additional integer allocation would then <em>not</em> cause memory usage to increase).</p> <p>My point here is that <em>you cannot call the memory usage results unexpected until you can fully define what the expected results are</em>. And this is not possible without looking at the source for <code>memory_get_usage</code>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload