• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Array Maximum Size?

 
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi.

Does anyone know if java places a maximum on the number of elements an array can potentially have?

Thanks
[ June 02, 2007: Message edited by: Sam Bluesman ]
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
see here
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmmmm... using the example, in the topic, that Fred referenced. It looks like there is a (slightly below) 2 gigabyte size limit for integer arrays.

For example, when I try this...


int[] j = new int[Integer.MAX_VALUE/4];



I get an out of memory condition. However, when I do this...



It works fine, even though this second case allocates more memory.

BTW, I used a "-Xmx20g" switch for the heap, so the out of memory condition is not due to the heap size.

Henry
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
BTW there are switches when you start java to specify thay you need more
memory. eg. java -Xms<size> <main-class>
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After playing around for a bit, it looks like the maximum array size is slightly less than 2 gigabytes -- for all array types. I can have almost twice as many elements of shorts than ints, twice as many elements of bytes than shorts, etc.

I don't have the exact number for elements, but it's close enough. And again, I used a very large heap, so the out of memory condition is not an out of heap memory condition.

Henry
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic