The following error is being shown:
"Exception in thread "main" java.lang.OutOfMemoryError: Java heap space"
when I declare:
long[] ar = new long[1000000000];
So how to declare an array which size is 10^9?
To create an array of one billion 8 bytes long
values you need at least 8 GB of free memory in the old generation. I suggest giving the heap at least 12 GB, if you have enough memory start with 32 GB.
if you don't have this much memory, you can use a memory mapped file on Linux, but most likely there is a more memory efficient way to store the data (depending on why you are trying to do this)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.