Answer the question
In order to leave comments, you need to log in
How to put a billion objects in a sheet?
Good day to all.
I sit torturing Java, in academic interests.
Faced with the fact that when trying to put a billion numbers in a sheet, I encounter:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
public class billion {
public static void main(String[] args){
ArrayList<Long> s = new ArrayList<Long>(1000000000);
for(long i = 0; i< 1000000000;i++){
s.add(i);
}
s.toString();
}
}
Answer the question
In order to leave comments, you need to log in
You just need at least 64 gigabytes of free RAM (if I counted everything correctly), but in fact four times more, since we store not primitives, but objects. Therefore, if you own such memory, then the keys for java -Xms128G -Xmx128G
Above are the correct answers. But why do you need such a list? Usually it is beaten into subsets and work already with them. Try changing the algorithm like this
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question