I'm writing a program that takes coordinates as input, and conceptualizes the coordinates in a grid, for which I'm using a 2D array. The problem is that some of the coordinates are larger than a billion, and I believe that the max size of a 2D array is somewhere around 800 million. I know that I can increase the memory allocated to the JVM to increase the max size; but is there a way to do this without going past the default max size, or another x by y grid system that doesn't have a max size? Thanks
Asked
Active
Viewed 49 times
-1
-
1Have you looked at [this similar question and the answers](http://stackoverflow.com/questions/674186/making-a-very-large-java-array)? – Hovercraft Full Of Eels Oct 03 '16 at 17:08
-
Why does your array match one index size to one coordinate step? Could you do some division so that your array is scaled? What about just keeping track of points? – matt Oct 03 '16 at 17:49
-
Option two: a sparse array as per [this similar question](http://stackoverflow.com/questions/22792097/alternatives-for-problems-involving-very-large-array-indexing-storing-very-large). – Hovercraft Full Of Eels Oct 03 '16 at 19:29
1 Answers
-1
Am I understanding you right? You would do something like this for (1,3)?
[0][0][1][0]
[0][0][0][0]
[0][0][0][0]
[0][0][0][0]
If your code requires an array of that size to store the coordinates, reconsider how your program works. One other way of storing coordinates with with an ArrayList or something where each entry would be a different occupied location in your array. That way you're only using memory for spots that are occupied and not ones that aren't. Because if you do it the way you plan, you'll be using 32 bits for EVERY coordinate on the grid when you KNOW most of them will be 0.

JitterbugChew
- 401
- 3
- 10
-
-
@HovercraftFullOfEels I can't use comments because of my rep, otherwise I would have used a comment for this clarification. – JitterbugChew Oct 03 '16 at 17:09
-
Yeah, I did modify it so I just needed the filled coordinates, I was just wondering if there was a way to make a bigger 2D array, or another data type I could use – Diego Tejada Oct 03 '16 at 17:20