Currently my app uses around 7 MB memory.
The array appears to use 700 KB if I check it size with strlen(serialize($array))))
.
If use this array within my app, and check memory usage (with memory_get_peak_usage()
) I get 14 MB.
If I don't use it, I get 7 MB.
If this array takes 700 KB serialized, why does PHP need 7 MB for this variable? Or am I doing the benchmark the wrong way?
You wanna steer away from PHP if this bothers you: http://nikic.github.com/2011/12/12/How-big-are-PHP-arrays-really-Hint-BIG.html. PHP arrays just like some living space.
When possible you could use SplFixedArray
, but then again who cares about what space a PHP array takes. If you are looking for clean / performance stuff why are you using PHP in the first place (yes this is coming from a PHP guy) :)
Serialized formats can do some memory optimization because they do not need to have the object exist in memory and to have it fully accessibility. They only keep the integrity of the data, not it's accessibility. If this helps to answer your question a little.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With