In php manual, I know that memory_get_usage(real_usage) Returns the amount of memory allocated to PHP, and set real_usage to TRUE to get total memory allocated from system, including unused pages.
I think, real usage should greater than allocated size. But my php script real usage less than allocated size and sometimes greater than allocated memory.
My code.
function p($var, $exit = false)
{
$trace = debug_backtrace();
$file = $trace[0]['file'];
$line = $trace[0]['line'];
if(is_bool($var)) {
$str = $var ? 'true' : 'false';
} else {
$str = print_r($var, true);
}
echo '<pre>';
echo $file . ' : ' . 'line #' . $line . '<br>';
echo $str;
echo '</pre>';
if($exit)
exit();
}
line 226: p(memory_get_usage());
line 227: p(memory_get_usage(true));
line 228: p(memory_get_peak_usage());
line 229: p(memory_get_peak_usage(true));
Result:
real usage less than allocated memory
real usage greater than allocated memory
I wonder why this happens. Thanks for help.