首页 > 解决方案 > 整数数组与单个整数?

问题描述

我目前在J2ME中表示128 位整数(需要创建数千万次),对象持有. 这比简单地使用 4 个单独的变量效率低吗?new int[4]

标签: javaoptimization

解决方案


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.


推荐阅读