Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

int array vs individual ints? [duplicate]

I am currently representing 128-bit integers in J2ME (which need to be created tens of millions of times) with objects holding a new int[4]. Is this reasonably less efficient than simply using 4 individual variables?

like image 535
0x777C Avatar asked Jun 13 '26 21:06

0x777C


1 Answers

If you have "tens of millions" of small arrays, then you have tens of millions of the array object overhead.

A int[4] would take a reference value (4 bytes), and an array (16 bytes overhead), so 10 million values would use 200 Mb extra space. If you run Java with lots of memory, so compressed OOPS cannot be used, the extra space use is higher.

To store a 128-bit value, I would recommend using two long fields.

like image 182
Andreas Avatar answered Jun 16 '26 06:06

Andreas