com.alexkasko.unsafe.offheaplong
public class OffHeapLongArray extends Object implements OffHeapLongAddressable, OffHeapDisposable, Iterable<Long>
Implementation of array of long using OffHeapMemory.
Default implementation uses sun.misc.Unsafe, with all operations guarded with assert keyword.
With assertions enabled in runtime (-ea java switch) AssertionError
will be thrown on illegal index access. Without assertions illegal index will crash JVM.
Array won't be zeroed after creation (will contain garbage by default).
Allocated memory may be freed manually using free() (thread-safe
and may be called multiple times) or it will be freed after OffHeapLongArray
will be garbage collected.
Note: while class implements Iterable, iterator will create new autoboxed Long object
on every next() call, this behaviour is inevitable with iterators in java 6/7.
| Modifier and Type | Field and Description |
|---|---|
private static int |
ELEMENT_LENGTH |
private OffHeapMemory |
ohm |
| Modifier | Constructor and Description |
|---|---|
|
OffHeapLongArray(long size)
Constructor
|
private |
OffHeapLongArray(OffHeapMemory ohm)
Private constructor for
clone() support |
| Modifier and Type | Method and Description |
|---|---|
OffHeapLongArray |
clone() |
void |
free()
Frees allocated memory, may be called multiple times from any thread
|
long |
get(long index)
Gets the element at position
index |
boolean |
isUnsafe()
Whether unsafe implementation of
OffHeapMemory is used |
OffHeapDisposableIterator<Long> |
iterator() |
void |
set(long index,
long value)
Sets the element at position
index to the given value |
long |
size()
Returns number of elements in array
|
String |
toString() |
private static final int ELEMENT_LENGTH
private final OffHeapMemory ohm
public OffHeapLongArray(long size)
size - number of elements in arrayprivate OffHeapLongArray(OffHeapMemory ohm)
clone() supportohm - cloned memory instancepublic boolean isUnsafe()
OffHeapMemory is usedOffHeapMemory is usedpublic long get(long index)
indexget in interface OffHeapAddressableindex - array indexpublic void set(long index, long value)
index to the given valueset in interface OffHeapLongAddressableindex - array indexvalue - long valuepublic long size()
size in interface OffHeapAddressablepublic void free()
free in interface OffHeapDisposablepublic OffHeapDisposableIterator<Long> iterator()
public OffHeapLongArray clone()
Copyright © 2014. All Rights Reserved.