This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Space complexity of an array of arrays Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Space complexity of an array of arrays" Watch "Space complexity of an array of arrays" New topic
Author

Space complexity of an array of arrays

Rusty Shackleford
Ranch Hand

Joined: Jan 03, 2006
Posts: 490
I was wondering about the number of bytes needed for an array of arrays. Given int vals[5][10] is S = 5*10*4bytes or is only the array of length 5 counted against the space requirements of a given method?


"Computer science is no more about computers than astronomy is about telescopes" - Edsger Dijkstra
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
Unless I am much mistaken, Java does not let you declare an array with fixed sizes. And it requires that you fix exactly one dimension when constructing an array. Java does not really have multi-dimensional arrays, but you can have arrays of arrays, which works similarly in some situations.



In addition, there is no way in Java to determine programmatically how many bytes are used by an array, or by anything else. That's considered low-level detail from which Java deliberately insulates the programmer.

For instance, while Java specifies the sizes of numbers that can be stored in an int as the range that fits in a 32-bit signed integer, it does NOT require that 32 bits are used to store an int. In 64-bit machines, an int might well be stored in 64 bits, for instance (but it still would be unable to hold bigger values).


Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3429
    
  12
a8 looks okay to me.


Joanne
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
Correct. I am just plain wrong on that. You can give more than one fixed dimension when constructing a Java array.
 
Don't get me started about those stupid light bulbs.
 
subject: Space complexity of an array of arrays
 
Similar Threads
In the API definition Of ArrayList what does E mean
arrays
array dimensions
Enhanced for loop
HELP!! Multidimensional Array Migraine