Welcome Guest, Not a member yet? Register   Sign In
Dubious about the {memory_usage} figure being reported
#1

[eluser]jedd[/eluser]
I'm seeing weirdness, and I suspect it's down to the way that PHP measures this - as I gather the templaty {memory_usage} output is just a wrapper around an extant PHP function.

A script that pulls in a 9.7MB xml file, and then churns around with it - duplicating probably 90% of it, and doing things like extracting and sorting through 23,000 arrays within that data structure, as well as various other HTML view rendering and so on - smugly reports, on completion, that it only used 1.3MB.

This is extra dubious because when my php.ini was set to allow 64MB process limit, I was getting errors - and had to bump it up to 100+.

I'm not hugely fussed about this, though it'd be nice to a) understand where the confusion lies, and b) have a clearer idea of actual memory usage while I'm developing.
#2

[eluser]Sayian[/eluser]
Could you provide the PHP version plz?

Thanks.
#3

[eluser]jedd[/eluser]
php 5.2.11
ci 1.7.2
apache 2.2.14
linux kernel 2.6.30
debian unstable
#4

[eluser]BrianDHall[/eluser]
You are correct on your wrapper suspicion, jedd. From profiler.php:

Code:
if (function_exists('memory_get_usage') && ($usage = memory_get_usage()) != '')
        {
            $output .= "<div style='color:#5a0099;font-weight:normal;padding:4px 0 4px 0'>".number_format($usage).' bytes</div>';
        }
        else
        {
            $output .= "<div style='color:#5a0099;font-weight:normal;padding:4px 0 4px 0'>".$this->CI->lang->line('profiler_no_memory_usage')."</div>";                
        }

http://php.net/manual/en/function.memory-get-usage.php

I suspect this might be a good part of the oddness:

Quote:Description

int memory_get_usage ([ bool $real_usage = false ] )
Returns the amount of memory, in bytes, that's currently being allocated to your PHP script.

Report a bug
Parameters

real_usage
Set this to TRUE to get the real size of memory allocated from system. If not set or FALSE only the memory used by emalloc() is reported.

I must admit I don't know what the hell emalloc() is or what the difference in 'real' memory usage is and this, but I bet it goes a long way to explaining your results.
#5

[eluser]jedd[/eluser]
Hmm, almost sounds like the function default is around the wrong way.

I found [url="http://marc.info/?l=php-internals&m=103334006314248&w=2"]this email[/url] from Rasmus himself! - describing emalloc / malloc differences. Quoting from that post:
Quote:malloc() is the normal system malloc() and emalloc() is a #define which points to
_emalloc() which is the internal safety net version. When you get memory
from emalloc(), even if you forget to free it, you won't leak because it
will be cleaned up for you at request end.

So, basically you should always use emalloc.

He has a caveat regarding third party libraries needing malloc calls to be safe, and this was posted in 2002 .. draw your own conclusions there.

In any case, it's probable that the guts of PHP uses emalloc for the most part - or at least did up until 2002 - and consequently the default memory_get_usage() function should be mostly insightful.

I might play around with the php functions a bit more and see if I can glean something useful.




Theme © iAndrew 2016 - Forum software by © MyBB