Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

memory usage of ArrayList<Integer>

I’m using ArrayList<Integer> in my research project. I need to keep unknown number of integers in this list. Sometimes I need to update the list: remove existing records or add new records. As Integer is an object, it’s taking much more memory than only int. Is there any alternate way to maintain the list that will consume less memory than Integer?

like image 529
user1539090 Avatar asked Oct 06 '12 20:10

user1539090


1 Answers

Try an integer list implementation that is optimized for memory usage, such as the one from the Colt library:

http://acs.lbl.gov/software/colt/api/cern/colt/list/IntArrayList.html

Java Integer objects usually require more overhead than an int primitive, so you need an implementation that is space-optimized.

From Colt:

Scientific and technical computing, as, for example, carried out at CERN, is characterized by demanding problem sizes and a need for high performance at reasonably small memory footprint. [...]

like image 72
jspcal Avatar answered Sep 22 '22 23:09

jspcal