note 57102 added to function.memory-get-usage
| From: | keith at NOTTHISPART dot easynews dot com | Date: | Fri, 23 Sep 2005 17:37:59 +0000 |
| Subject: | note 57102 added to function.memory-get-usage | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-95666@lists.php.net to get a copy of this message | ||
There doesn't seem to be a nice function to find out how much memory a specific variable uses
so after a bit of searching I found a message about arrays taking 42 bytes per element. I
don't know if this is accurate at all but I made a function that incorporates this to give me
the size of an array variable:
<?php
function arrayMemUsage( &$array ) {
$memSize = 0;
if(is_array($array)) {
foreach($array as $aKey => $aValue) {
if(is_array($aValue)) {
$memSize += arrayMemUsage( $aValue );
} else {
$memSize += strlen( $aValue );
}
$memSize += strlen($aKey);
}
return $memSize + (42 * count($array));
} else {
return strlen($array);
}
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.memory-get-usage.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+57102
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+57102&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+57102&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+57102&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+57102&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+57102&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+57102&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+57102&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+57102&report=yes
Search -- http://master.php.net/manage/user-notes.php