com.alexkasko.unsafe.offheap
class DirectOffHeapMemory extends OffHeapMemory
OffHeapMemory using ByteBuffer.allocateDirect(int)| Modifier and Type | Field and Description |
|---|---|
private ByteBuffer |
bb |
private Method |
clean |
private Object |
cleaner |
private AtomicBoolean |
disposed |
private long |
length |
| Constructor and Description |
|---|
DirectOffHeapMemory(long bytes) |
| Modifier and Type | Method and Description |
|---|---|
OffHeapMemory |
clone()
Creates new instance of
OffHeapMemory
and copies there current instance contents |
void |
copy(long offset,
OffHeapMemory destination,
long destOffset,
long bytes)
Copies memory from this instance's area into another instance's area
|
void |
free()
Frees allocated memory, may be called multiple times from any thread
|
void |
get(long offset,
byte[] buffer)
Copies part of memory area into byte array
|
void |
get(long offset,
byte[] buffer,
int bufferOffset,
int bytes)
Copies part of memory area into byte array
|
byte |
getByte(long offset)
Gets byte from memory area
|
int |
getInt(long offset)
Gets four bytes from memory area as int
|
long |
getLong(long offset)
Gets eight bytes from memory area as long
|
short |
getShort(long offset)
Gets two bytes from memory area as short
|
short |
getUnsignedByte(long offset)
Gets one byte (stored as one signed byte), converts it to unsigned
and returns it as short
|
long |
getUnsignedInt(long offset)
Gets unsigned int (stored as 4 bytes) and returns it as long
|
int |
getUnsignedShort(long offset)
Gets unsigned short from memory area (stored as two bytes) and returns it as int
|
boolean |
isUnsafe()
Whether current implementation uses
sun.misc.Unsafe |
long |
length()
Returns length of allocated memory area
|
void |
put(long offset,
byte[] buffer)
Copies byte array contents into memory area
|
void |
put(long offset,
byte[] buffer,
int bufferOffset,
int bytes)
Copies byte array contents into memory area
|
void |
putByte(long offset,
byte value)
Puts byte into memory area
|
void |
putInt(long offset,
int value)
Puts int into memory area as four bytes
|
void |
putLong(long offset,
long value)
Puts long into memory area as eight bytes
|
void |
putShort(long offset,
short value)
Puts short into memory area as two bytes
|
void |
putUnsignedByte(long offset,
short value)
Puts short with value from 0 to 255 inclusive into memory area as one
signed byte
|
void |
putUnsignedInt(long offset,
long value)
Puts long value from 0 to 4294967295 inclusive into memory area as four bytes
|
void |
putUnsignedShort(long offset,
int value)
Puts int with value from 0 to 65535 inclusive into memory are as two bytes
|
private void |
setupAndroidCleaner() |
private void |
setupOpenJdkCleaner() |
String |
toString() |
allocateMemory, allocateMemoryDirect, allocateMemoryOnHeap, allocateMemoryUnsafeprivate final ByteBuffer bb
private final long length
private final AtomicBoolean disposed
DirectOffHeapMemory(long bytes)
private void setupOpenJdkCleaner() throws Exception
Exceptionprivate void setupAndroidCleaner() throws Exception
Exceptionpublic boolean isUnsafe()
sun.misc.UnsafeisUnsafe in class OffHeapMemorypublic long length()
length in class OffHeapMemorypublic void free()
free in class OffHeapMemorypublic void put(long offset, byte[] buffer, int bufferOffset, int bytes)
put in class OffHeapMemoryoffset - memory area offsetbuffer - source byte arraybufferOffset - position in byte arraybytes - bytes length to copypublic void put(long offset, byte[] buffer)
put in class OffHeapMemoryoffset - memory area offsetbuffer - source byte arraypublic void get(long offset, byte[] buffer, int bufferOffset, int bytes)
get in class OffHeapMemoryoffset - memory area offsetbuffer - destination byte arraybufferOffset - position in byte arraybytes - bytes length to copypublic void get(long offset, byte[] buffer)
get in class OffHeapMemoryoffset - memory area offsetbuffer - destination byte arraypublic byte getByte(long offset)
getByte in class OffHeapMemoryoffset - memory area offsetpublic void putByte(long offset, byte value)
putByte in class OffHeapMemoryoffset - memory area offsetvalue - byte valuepublic short getUnsignedByte(long offset)
getUnsignedByte in class OffHeapMemoryoffset - memory area offsetpublic void putUnsignedByte(long offset, short value)
putUnsignedByte in class OffHeapMemoryoffset - memory area offsetvalue - unsigned byte as shortpublic short getShort(long offset)
getShort in class OffHeapMemoryoffset - memory area offsetpublic void putShort(long offset, short value)
putShort in class OffHeapMemoryoffset - memory area offsetvalue - short valuepublic int getUnsignedShort(long offset)
getUnsignedShort in class OffHeapMemoryoffset - memory area offsetpublic void putUnsignedShort(long offset, int value)
putUnsignedShort in class OffHeapMemoryoffset - memory area offsetvalue - unsigned short as intpublic int getInt(long offset)
getInt in class OffHeapMemoryoffset - memory area offsetpublic void putInt(long offset, int value)
putInt in class OffHeapMemoryoffset - memory area offsetvalue - int valuepublic long getUnsignedInt(long offset)
getUnsignedInt in class OffHeapMemoryoffset - memory area offsetpublic void putUnsignedInt(long offset, long value)
putUnsignedInt in class OffHeapMemoryoffset - memory area offsetvalue - unsigned int as longpublic long getLong(long offset)
getLong in class OffHeapMemoryoffset - memory area offsetpublic void putLong(long offset, long value)
putLong in class OffHeapMemoryoffset - memory area offsetvalue - long valuepublic void copy(long offset, OffHeapMemory destination, long destOffset, long bytes)
copy in class OffHeapMemoryoffset - this memory area offsetdestination - destination memory areadestOffset - destination memory area offsetbytes - memory length in bytes to copypublic OffHeapMemory clone()
OffHeapMemory
and copies there current instance contentsclone in class OffHeapMemoryOffHeapMemoryCopyright © 2014. All Rights Reserved.