• 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:

Maximum size of array and arraylist..?

 
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear all
what is the maximum size of array and ArrayList is it depends on the size of heap pleaes just go through the code

In this code the i had added plus 2 to the size of total memory int int array but my code is not giving outofmemory error
Please help me
 
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Runtime.getRuntime().getMemory()
There is no method like "getMemory()" in Runtime class.
What you need is max memory allocated to JVM and find it using "maxMemory()" method, and then assign this max memory to array, you'll get OutOfMemory exception.
 
santhosh.R gowda
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry for ht ewrong method entry i had given totalMemory() only but its not giving error
 
Sagar Rohankar
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I tried this code, ant it successfully throwing an exception !! Which code your trying ? Can you use "maxMemory()" ?
 
santhosh.R gowda
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ya its throwing error but when we use size less than maxMemory() ie 666501109 also its throwing error we are not getting the exact value of the size limit please give me the exact number(maximum size) that the array will not throw error up to that value
 
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Arrays are non-negative integer indexed , so maximum array size you can access would be Integer.MAX_VALUE/2. The other thing is how big array you can create. It depends on the maximum memory available to your VM and the content type of the array. Each array element has its size, eg. byte = 1 byte, int = 4 bytes, Object reference = 4 bytes (on a 32 bit system). So if you have 1 MB memory available on your machine, you could allocate an array of byte[1024 * 1024] or Object[256 * 1024]. Answering your question - you can allocate an array of size (maximum available memory / size of array item).
 
Marshal
Posts: 80619
469
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Adam Michalik wrote:Arrays are non-negative integer indexed , so maximum array size you can access would be Integer.MAX_VALUE/2.

Integer.MAX_VALUE, surely? Not divided by 2.
 
Adam Michalik
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, of course (I had in mind that the maximum value is half of the total possible integer numbers)
 
santhosh.R gowda
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


" Adam Michalik wrote
Object reference = 4 bytes (on a 32 bit system)


I think its 8 bytes right for 32 bit system and 16 bytes for 64 bit system

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

santhosh.R gowda wrote:

Adam Michalik wrote:
Object reference = 4 bytes (on a 32 bit system)


I think its 8 bytes right for 32 bit system and 16 bytes for 64 bit system


After some research, I'm not so sure it is explicitly determined. See the other thread.
On the other hand, on a 32 bit system, a memory pointer takes 4 bytes, so I don't know if it was reasonable to have 8 byte references... What's more, an 8-byte reference would not fit into a 32-bit processor register, which in turn would be slowing down object reference resolution. Do you have any more info on usage of 8-byte references on a 32-bit system?
 
reply
    Bookmark Topic Watch Topic
  • New Topic