简体   繁体   English

Java中大于二维数组的二维网格

[英]2D Grid Larger than 2D Array in Java

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.我正在编写一个程序,该程序将坐标作为输入,并将网格中的坐标概念化,为此我使用了 2D 数组。 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.问题是有些坐标大于 10 亿,我相信 2D 数组的最大大小在 8 亿左右。 I know that I can increase the memory allocated to the JVM to increase the max size;我知道我可以增加分配给 JVM 的内存来增加最大大小; 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?但是有没有办法在不超过默认最大尺寸或另一个没有最大尺寸的 x by y 网格系统的情况下做到这一点? Thanks谢谢

Am I understanding you right?我理解你对吗? You would do something like this for (1,3)?你会为 (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.另一种存储坐标的方法是使用 ArrayList 或其他东西,其中每个条目将是数组中不同的占用位置。 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.因为如果你按照你的计划来做,当你知道网格上的每个坐标都是 0 时,你将使用 32 位。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM