如何让我没有跑出来一个大的内存阵列3D? [英] How do I make a large 3D array without running out of memory?

查看:145
本文介绍了如何让我没有跑出来一个大的内存阵列3D?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下方式:

public static void createGiantArray(int size) {
    int[][][] giantArray = new int[size][size][size];
}

当我与一个大小为10,000像这样称呼它:

When I call it with a size of 10,000 like so:

createGiantArray(10000);

我收到以下错误:

I get the following error:

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space

我怎样才能创建一个数组,它是10,000×10,000×万,而绕过内存异常?

How can I create an array that is 10,000 x 10,000 x 10,000 while bypassing the memory exception?

(我知道我目前的方法是没有意义的,失去范围。我没有张贴额外的code与它去)。

(I am aware my current method is pointless and loses scope. I didn't post the extra code that goes with it.)

推荐答案

如果该数据将是比较稀疏,那么你可以使用不同的数据结构,如描述的这里或<一个href=\"http://stackoverflow.com/questions/12626135/memory-efficient-sparse-array-in-java\">here.

If the data is going to be relatively sparse, then you can use a different data structure, like described here or here.

这篇关于如何让我没有跑出来一个大的内存阵列3D?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆