0

  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.

Gray Su
  • 101
  • 1
  • 4
  • What was done differently between the two screenshots? I'm assuming this is Windows based on the slash direction? – Devon Bessemer Sep 10 '17 at 15:19
  • First screenshot , the real usage is 2097152B and allocated memory is 8124592B. Second screenshot ,the real usage is 10485760B and allocated memory is 8126512B. – Gray Su Sep 11 '17 at 11:33

0 Answers0