So I have a big list of integers I have to work with (in the order of 70Mb). As a part of the process of reading them, I need to temporarily store them. I can either spread them over several IntBuffers, or allocate a couple of large arrays.
I couldn't find any documentation however on how an IntBuffer compares to an array in terms of memory usage (with all the metadata that java adds). Does anyone know anything about this?
There is very little difference between a int[] and a heap IntBuffer or a direct IntBuffer in terms of memory usage esp if the arrays are large. (There is a small over head)
In terms of performance int[] is the fastest and a direct IntBuffer with native byte ordering is the second fastest. The advantage of the IntBuffer is that its off heap and you can have much larger sizes e.g. 70 GB without increasing the heap size or the Full GC times.
For a 70 MB array, it small enough that the simplest solution int[] is likely to be the best. (It will also be the easiest to write and most efficient to run)
Relative to 70MB of ints, the metadata an IntBuffer adds is nothing. But a profiler will give you a more complete answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With