I recenty came across sun.misc.Unsafe
class, allowing user to allocate,deallocate and in general access memory in a similar fashion like in C. I read in a couple of blogs that tackle this issue e.g.
- Which is faster - heap or direct memory - test results claim heap
- Off-heap memory vs DirectByteBuffer vs Heap - Off-heap seems to be fastest
- Memory mapped files for time series data -
MappedByteBuffer
faster than heap objects
Article 1) seems to be in contradiction with the other ones and I fail to comprehend why. DirectMemoryBuffer is using sun.misc.Unsafe
under the hood (so is MappedByteBuffer
), so they should also suffer from JNI calls as described in article 1. Also, in article 2, the Off-heap memory accesses resemble the ones in article 1, and give completely opposite results.
Could someone generally comment on how to proceed with Off-heap memory i.e. when to use it, is there a significant benefit to it, and most importantly, why similar subject gives highly different results based on the articles above? Thanks.