Package com.alexkasko.unsafe.offheap

Off-heap memory operations using sun.misc.Unsafe

See: Description

Package com.alexkasko.unsafe.offheap Description

Off-heap memory operations using sun.misc.Unsafe

This package contains OffHeapMemory frontend class for working with off-heap memory: allocation, immediate deallocation, reading/writing primitives and byte arrays.

Implementations

Main implementation (UnsafeOffHeapMemory) uses Unsafe, fallback implementation (DirectOffHeapMemory) uses DirectByteBuffers, additional on-heap implementation (OnHeapMemory) uses byte arrays.

Boundary checks

With Unsafe backend all operations have boundary checks using assert keyword. With assertions enabled in runtime (-ea java switch) illegal memory access will thow AssertionError. Without assertions illegal memory access will crash JVM.

Fallback implementation

Fallback implementation have some drawbacks comparing with unsafe one:

On-heap implementation

On-heap implementation added for rare cases when the same API is required for small on-heap collection. It may not allocate more than Integer.MAX_VALUE memory.

Data structures

OffHeapMemory is used as a base for off-heap data structures, see com.alexkasko.unsafe.offheaplong and com.alexkasko.unsafe.offheapstruct packages.

Additional utility classes

Usage example (in tests): github link

Copyright © 2014. All Rights Reserved.