I have to create 1000 heaps, each of which can contain 10^6 nodes. For easy access of the nodes, for deletion of nodes and for updating keys of nodes, I am planning to create a 2D array of size 10^6 * 1000 in which I'll be storing the references of nodes. But, is an array of such a big size possible to create in Java? Is there a better way to access a particular node from the heaps without creating an array? I could go through each node of the heap in order to search for my node, but this process will be of the order n for 1 heap, and if I have to perform a deletion of a particular node from all heaps, the process would take be of the order 1000*n.
Asked
Active
Viewed 1,744 times
2 Answers
0
Java arrays are indexed by int
s, so the maximum index is 2^31 - 1
, which is 2147483647 (approx. 2E9), so you should be ok with your 1E9 sized array. However, you'll need to have enough RAM, don't forget a billion long
s will take 8GB of ram.
There's a much more detailed discussion in Do Java arrays have a maximum size?

Community
- 1
- 1

davidsheldon
- 38,365
- 4
- 27
- 28
0
If you need more memory than max value of int you can use sun.misc.Unsafe. See here: https://dzone.com/articles/understanding-sunmiscunsafe

Gerrit
- 365
- 1
- 3
- 19