Results 1 to 5 of 5

Thread: array storage bytes of memory

  1. #1

    Thread Starter
    Addicted Member annie613's Avatar
    Join Date
    May 2003
    Location
    NY, NY
    Posts
    161

    array storage bytes of memory

    I am not sure if I even really need to know this for programming java, but its bothering me not to know...

    i know that an int stores 4 bytes of memory and a char stores 2 bytes...

    is it the same for an array???
    like if int a[100];
    does mean we give 100 cells * 4 bytes of memory???

    annie

  2. #2
    Fanatic Member
    Join Date
    Jan 2003
    Posts
    1,004
    If it were C++, then yes, but it isn't exactly so with Java. There are some overhead components (for example, length) that are stored with the allocation.

    At least to the best of my abilities, I believe this is the case...
    "Can't" and "shouldn't" are two totally separate things.

    All questions should be answered. All answers should be true. That is why I post.

  3. #3

    Thread Starter
    Addicted Member annie613's Avatar
    Join Date
    May 2003
    Location
    NY, NY
    Posts
    161
    bytes of memory reserved for int a[100]
    is like a.length or a.length()

    i am sure i should be focusing on more important concepts of the array but it was just one of those things that plays on your mind when you cant focus on what is really important

    thanks

  4. #4
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    Yes Darkwraith is right. There is some overhead when the VM allocates memory for certain types. I remember once reading somewhere that when a byte[] b array is declared(or anything smaller than int) the vm actually allocates multiples of four bytes for any array having length > 1 or if length == 1 then just four bytes are allocated.

  5. #5

    Thread Starter
    Addicted Member annie613's Avatar
    Join Date
    May 2003
    Location
    NY, NY
    Posts
    161
    'nothing in the universe is as diverse as a byte of data'

Posting Permissions

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



Click Here to Expand Forum to Full Width