I have:
我有:
int [][] lengths=null;
I have to initialize this based on runtime parameter.
我必须根据运行时参数初始化它。
I am getting OutOfMemoryException
when my array size something like int[13000][130000]
or more.
当我的数组大小像int [13000] [130000]或更多时,我得到OutOfMemoryException。
Is there a way to come around this or any other approach I can take ?
有没有办法绕过这个或任何其他方法我可以采取?
3 个解决方案
#1
1
Note: this should not prevent the OutOfMemoryError
but you need to learn about the JVM
memory arguments, because it should help for any case.
注意:这不应该阻止OutOfMemoryError,但是你需要了解JVM内存参数,因为它应该对任何情况都有帮助。
You need to take a look at the JVM
memory parameters. actually you can set the as much memory as you want to your JVM
:
您需要查看JVM内存参数。实际上,您可以根据需要为JVM设置尽可能多的内存:
-Xmx2048m -> this param to set the max memory that the JVM can allocate
-Xms1024m -> the init memory that JVM will allocate on the start up
-XX:MaxPermSize=512M -> this for the max Permanent Generation memory
and you may want to check this parameters also.
并且您可能还想检查此参数。
-XX:MaxNewSize= -> this could be 40% from your Xmx value
-XX:NewSize=614m -> this could be 40% from your Xmx value
also you may tell you JVM
what type of GC
to use like (i think its already use by default in the earlier versions)
你也可以告诉你JVM使用什么类型的GC(我认为它在早期版本中默认使用)
-XX:+UseConcMarkSweepGC
#2
0
If it isn't absolutely neccessary for you to fill every single cell of this grid, nested lists might be a smarter approach. Think of it as an 1D-array filled with 1D-arrays of various size. As a data type, they are especially useful for values provided during runtime, so if you don't want to or are not allowed to increase your mem cap as described in Salahs answer, think of this as an alternative.
如果您不是绝对需要填充此网格的每个单元格,嵌套列表可能是一种更智能的方法。可以把它想象成一个充满各种大小的1D阵列的一维阵列。作为一种数据类型,它们对于在运行时提供的值特别有用,因此如果您不希望或不允许按照Salahs答案中的描述增加您的内存上限,请将此视为替代方案。
#3
0
An integer takes 4 byte of memory. You want to allocate 4 Byte * 13000 * 130000 = 6760000000 Byte
. That are ~6,5 gigabyte of memory.
整数需要4个字节的内存。您想要分配4个字节* 13000 * 130000 = 6760000000字节。那是~6,5千兆字节的内存。
If your computer has that amount of memory, there exist JVM parameters to increase the maximum used by the JVM.
如果您的计算机具有该内存量,则存在JVM参数以增加JVM使用的最大值。
#1
1
Note: this should not prevent the OutOfMemoryError
but you need to learn about the JVM
memory arguments, because it should help for any case.
注意:这不应该阻止OutOfMemoryError,但是你需要了解JVM内存参数,因为它应该对任何情况都有帮助。
You need to take a look at the JVM
memory parameters. actually you can set the as much memory as you want to your JVM
:
您需要查看JVM内存参数。实际上,您可以根据需要为JVM设置尽可能多的内存:
-Xmx2048m -> this param to set the max memory that the JVM can allocate
-Xms1024m -> the init memory that JVM will allocate on the start up
-XX:MaxPermSize=512M -> this for the max Permanent Generation memory
and you may want to check this parameters also.
并且您可能还想检查此参数。
-XX:MaxNewSize= -> this could be 40% from your Xmx value
-XX:NewSize=614m -> this could be 40% from your Xmx value
also you may tell you JVM
what type of GC
to use like (i think its already use by default in the earlier versions)
你也可以告诉你JVM使用什么类型的GC(我认为它在早期版本中默认使用)
-XX:+UseConcMarkSweepGC
#2
0
If it isn't absolutely neccessary for you to fill every single cell of this grid, nested lists might be a smarter approach. Think of it as an 1D-array filled with 1D-arrays of various size. As a data type, they are especially useful for values provided during runtime, so if you don't want to or are not allowed to increase your mem cap as described in Salahs answer, think of this as an alternative.
如果您不是绝对需要填充此网格的每个单元格,嵌套列表可能是一种更智能的方法。可以把它想象成一个充满各种大小的1D阵列的一维阵列。作为一种数据类型,它们对于在运行时提供的值特别有用,因此如果您不希望或不允许按照Salahs答案中的描述增加您的内存上限,请将此视为替代方案。
#3
0
An integer takes 4 byte of memory. You want to allocate 4 Byte * 13000 * 130000 = 6760000000 Byte
. That are ~6,5 gigabyte of memory.
整数需要4个字节的内存。您想要分配4个字节* 13000 * 130000 = 6760000000字节。那是~6,5千兆字节的内存。
If your computer has that amount of memory, there exist JVM parameters to increase the maximum used by the JVM.
如果您的计算机具有该内存量,则存在JVM参数以增加JVM使用的最大值。