• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Java array memory allocation

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

What will happen when you do


Or in other words can we allocate such large arrays.

Thanks,
Martin
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If there's enough memory available, yes. You may have to use Sun's -Xmx switch (or another vendor-specific mechanism) to set the max size of the Java heap.
 
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

The last I remember I had a question along similar lines and Jim Yingst pointed that as array object have length field which is of type 'int' we can only create arrays of len Integer.MAX_VALUE. Again this is true only if we have sufficient memory to create Integer.MAX_VALUE size array.

I ran the following,


and got,
java.lang.OutOfMemoryError
Exception in thread "main"

Regards
Maulin
[ March 04, 2005: Message edited by: Maulin Vasavada ]
 
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Maulin Vasavada:
byte[] b = new byte[Integer.MAX_VALUE];

Yes well, not everyone has 2GB of RAM devoted exclusively to the JVM!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic