File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Space complexity of an array of arrays

 
Rusty Shackleford
Ranch Hand
Posts: 490
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Peter Chase
Ranch Hand
Posts: 1970
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Joanne Neal
Rancher
Pie
Posts: 3742
16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
a8 looks okay to me.
 
Peter Chase
Ranch Hand
Posts: 1970
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Correct. I am just plain wrong on that. You can give more than one fixed dimension when constructing a Java array.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic