See: Description
| Interface | Description |
|---|---|
| OffHeapAddressable |
Basic interface for off-heap long-indexed collections.
|
| OffHeapDisposable |
Basic interface for off-heap classes that support manual memory freeing.
|
| OffHeapDisposableIterable<T> |
Interface for iterables over off-heap collections those can be disposed manually
|
| OffHeapDisposableIterator<T> |
Interface for iterators over off-heap collections those can be disposed manually
|
| Class | Description |
|---|---|
| DirectOffHeapMemory |
Implementation of
OffHeapMemory using ByteBuffer.allocateDirect(int) |
| OffHeapMemory |
Allocates an area of off-heap memory that is not a subject to GC.
|
| OffHeapUtils |
Static utility methods for off-heap classes
|
| OffHeapUtils.EmptyDisposableIterator<T> |
Returns empty instance of
OffHeapDisposableIterator |
| OnHeapMemory |
Implementation of
OffHeapMemory
using byte array effectively making it OnHeap memory |
| UnsafeOffHeapMemory |
Implementation of
OffHeapMemory 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.
Main implementation (UnsafeOffHeapMemory) uses Unsafe,
fallback implementation (DirectOffHeapMemory) uses DirectByteBuffers,
additional on-heap implementation (OnHeapMemory) uses byte arrays.
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 have some drawbacks comparing with unsafe one:
Integer.MAX_VALUEDirectByteBuffer
is garbage collector; this library uses reflection hacks
(different for OpenJDK and Android implementations) to free memory eagerlyOn-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.
OffHeapMemory is used as a base for off-heap data structures, see com.alexkasko.unsafe.offheaplong
and com.alexkasko.unsafe.offheapstruct packages.
OffHeapUtils: allows freeing memory quietly checking null on provided instanceOffHeapDisposable: interface for freeable classesUsage example (in tests): github link
Copyright © 2014. All Rights Reserved.