note 102134 added to function.memory-get-usage

From: Date: Fri, 28 Jan 2011 14:25:13 +0000
Subject: note 102134 added to function.memory-get-usage
Groups: php.notes 
Request: Send a blank email to php-notes+get-176426@lists.php.net to get a copy of this message
This comment concerns my function memory_get_usage_by_variable(). ------------------------------------------------------------------ I use the following function to determine the rough memory-usage of single variables when debugging, optimizing my code, or searching for memory-leaks. Maybe, it can be helpful to some of you or you can develop it further for your personal needs. When using the function for the first time the variable-sizes may differ by 48 bytes, because that seems to be the amount of memory PHP needs to address a function at runtime. Note: The function needs PHP v5.1 or higher, since, a try-and-catch-block is used around serializing arrays of unknown type. Attention: The function duplicates the delivered variable in order to determine its memory-usage and it may blow up your memory-limit when working with "huge" variables. To prevent this behaviour you may write a condition at the beginning of the function using memory_get_usage(false) and ini_get("memory_limit") in order to check if PHP already used most of its available memory... I was too lazy to do that, since, for my needs, this function does what it should do: It helps me identifying where my code (i.e. my variables) uses a lot of / the most memory. The "bigger" the input-variables, the more "accurate" the output of this function will be. ---- Server IP: 69.147.83.197 Probable Submitter: 87.159.108.91 ---- Manual Page -- http://www.php.net/manual/en/function.memory-get-usage.php Edit -- https://master.php.net/note/edit/102134 Del: integrated -- https://master.php.net/note/delete/102134/integrated Del: useless -- https://master.php.net/note/delete/102134/useless Del: bad code -- https://master.php.net/note/delete/102134/bad+code Del: spam -- https://master.php.net/note/delete/102134/spam Del: non-english -- https://master.php.net/note/delete/102134/non-english Del: in docs -- https://master.php.net/note/delete/102134/in+docs Del: other reasons-- https://master.php.net/note/delete/102134 Reject -- https://master.php.net/note/reject/102134 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#176426) next »