com.alexkasko.unsafe.offheap
class UnsafeOffHeapMemory extends OffHeapMemory
OffHeapMemory
using sun.misc.Unsafe
Modifier and Type | Field and Description |
---|---|
private long |
address |
private static int |
BYTE_ARRAY_OFFSET |
private AtomicBoolean |
disposed |
private long |
length |
private static sun.misc.Unsafe |
UNSAFE |
Constructor and Description |
---|
UnsafeOffHeapMemory(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
|
protected void |
finalize() |
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
|
String |
toString() |
allocateMemory, allocateMemoryDirect, allocateMemoryOnHeap, allocateMemoryUnsafe
private static final sun.misc.Unsafe UNSAFE
private static final int BYTE_ARRAY_OFFSET
private final long address
private final long length
private final AtomicBoolean disposed
UnsafeOffHeapMemory(long bytes)
public boolean isUnsafe()
sun.misc.Unsafe
isUnsafe
in class OffHeapMemory
public long length()
length
in class OffHeapMemory
public void free()
free
in class OffHeapMemory
public void put(long offset, byte[] buffer, int bufferOffset, int bytes)
put
in class OffHeapMemory
offset
- memory area offsetbuffer
- source byte arraybufferOffset
- position in byte arraybytes
- bytes length to copypublic void put(long offset, byte[] buffer)
put
in class OffHeapMemory
offset
- memory area offsetbuffer
- source byte arraypublic void get(long offset, byte[] buffer, int bufferOffset, int bytes)
get
in class OffHeapMemory
offset
- memory area offsetbuffer
- destination byte arraybufferOffset
- position in byte arraybytes
- bytes length to copypublic void get(long offset, byte[] buffer)
get
in class OffHeapMemory
offset
- memory area offsetbuffer
- destination byte arraypublic byte getByte(long offset)
getByte
in class OffHeapMemory
offset
- memory area offsetpublic void putByte(long offset, byte value)
putByte
in class OffHeapMemory
offset
- memory area offsetvalue
- byte valuepublic short getUnsignedByte(long offset)
getUnsignedByte
in class OffHeapMemory
offset
- memory area offsetpublic void putUnsignedByte(long offset, short value)
putUnsignedByte
in class OffHeapMemory
offset
- memory area offsetvalue
- unsigned byte as shortpublic short getShort(long offset)
getShort
in class OffHeapMemory
offset
- memory area offsetpublic void putShort(long offset, short value)
putShort
in class OffHeapMemory
offset
- memory area offsetvalue
- short valuepublic int getUnsignedShort(long offset)
getUnsignedShort
in class OffHeapMemory
offset
- memory area offsetpublic void putUnsignedShort(long offset, int value)
putUnsignedShort
in class OffHeapMemory
offset
- memory area offsetvalue
- unsigned short as intpublic int getInt(long offset)
getInt
in class OffHeapMemory
offset
- memory area offsetpublic void putInt(long offset, int value)
putInt
in class OffHeapMemory
offset
- memory area offsetvalue
- int valuepublic long getUnsignedInt(long offset)
getUnsignedInt
in class OffHeapMemory
offset
- memory area offsetpublic void putUnsignedInt(long offset, long value)
putUnsignedInt
in class OffHeapMemory
offset
- memory area offsetvalue
- unsigned int as longpublic long getLong(long offset)
getLong
in class OffHeapMemory
offset
- memory area offsetpublic void putLong(long offset, long value)
putLong
in class OffHeapMemory
offset
- memory area offsetvalue
- long valuepublic void copy(long offset, OffHeapMemory destination, long destOffset, long bytes)
copy
in class OffHeapMemory
offset
- 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 OffHeapMemory
OffHeapMemory
Copyright © 2014. All Rights Reserved.