http://php.net/manual/de/function.memory-get-peak-usage.php
point out that by default the value from emalloc()
(memory manager written in c++) will be returned.
In what cases should I use true
as parameter?
http://php.net/manual/de/function.memory-get-peak-usage.php
point out that by default the value from emalloc()
(memory manager written in c++) will be returned.
In what cases should I use true
as parameter?
As far as my understanding goes here is the answer:
memory_get_peak_usage(true)
when you need to find out the WHOLE usage of your app, including all kinds of overheads and etc. It's handy when you want to find out how heavy your app is. true
usually rounds up numbers to the bigger size, because you can't just allocate 729 KiloBytes from RAM, your app takes whole 1024 KiloBytes.
memory_get_peak_usage()
is handy when you want to find out which 'method' of execution is most lightweight, so you can cram as much actions as possible into the 1024 KiloBytes that are already allocated.
It is hard to find specific information about this on the web, so wanted to share some findings here, even though it's an old question.
When debugging "Allowed Memory Size of X Bytes Exhausted"-error we want to figure out where in our script the memory is high, as it means we use more memory as the memory_limit setting.
For this the memory_get_peak_usage function is convenient, as it shows how much memory we used when we used the most.
The right value for debugging exceeding memory_limit is memory_get_peak_usage(true) (with the true parameter). If this value is exceeded the memory_limit for PHP is reached, and the fatal error "Allowed memory size of X Bytes Exhausted" will be thrown.