Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jan 2005
    Posts
    470
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Question 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?

  • #2
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    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.

  • #3
    Regular Coder ralph l mayo's Avatar
    Join Date
    Nov 2005
    Posts
    951
    Thanks
    1
    Thanked 31 Times in 29 Posts
    You can measure the memory used in the whole process of creating and storing the array:
    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); 
    edit: I don't know if that function is portable or not. Works on Linux.
    Last edited by ralph l mayo; 09-06-2007 at 12:04 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •