Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
09-05-2007, 08:28 PM #1
- Join Date
- Jan 2005
- Thanked 0 Times in 0 Posts
Determining memory used by an array
Is there any way I can determine the amount of memory used by an array?
For instance, if I did a database lookup that returned 100,000 integers into one big array. How can tell how much memory that is taking up?
09-05-2007, 09:23 PM #2
- Join Date
- Aug 2003
- One step ahead of you.
- Thanked 3 Times in 3 Posts
Not really possible.
I'm not sure if this was any help, but I hope it didn't make you stupider.
Experience is something you get just after you really need it.
PHP Installation Guide Feedback welcome.
09-06-2007, 01:01 AM #3
You can measure the memory used in the whole process of creating and storing the array:
edit: I don't know if that function is portable or not. Works on Linux.PHP Code:
$initial_mem = memory_get_usage();
/* do some stuff here to set up the array */
echo 'Cost of the array + whatever other uncollected structs we incurred building it: ' . (memory_get_usage() - $initial_mem);
Last edited by ralph l mayo; 09-06-2007 at 01:04 AM.