note 57102 deleted from function.memory-get-usage by nlopess

From: Date: Sat, 24 Sep 2005 07:51:11 +0000
Subject: note 57102 deleted from function.memory-get-usage by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-95686@lists.php.net to get a copy of this message
Note Submitter: keith at NOTTHISPART dot easynews dot com Reason: bad code ---- 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); } } ?>

« previous php.notes (#95686) next »