public interface NativeMemory extends AutoCloseable
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes the memory.
|
boolean |
compareAndSet(long offset,
byte[] data) |
boolean |
compareAndSet(long offset,
byte expect,
byte update)
compares the value at offset with expect if equal sets the value at offset to update and returns true otherwise return false.
|
boolean |
compareAndSet(long offset,
int expect,
int update)
compares the value at offset with expect if equal sets the value at offset to update and returns true otherwise return false.
|
boolean |
compareAndSet(long offset,
long expect,
long update)
compares the value at offset with expect if equal sets the value at offset to update and returns true otherwise return false.
|
boolean |
compareAndSet(long offset,
short expect,
short update)
compares the value at offset with expect if equal sets the value at offset to update and returns true otherwise return false.
|
long |
compareAndSet16ByteAlignment() |
long |
compareAndSet1ByteAlignment()
Returns the amount of alignment needed for addresses to do 1 byte atomic operations on (if supported by cpu)
|
long |
compareAndSet2ByteAlignment()
Returns true if the cpu can do 2 byte atomic operations.
|
long |
compareAndSet4ByteAlignment()
Returns the amount of alignment needed for addresses to do 4 byte atomic operations on (if supported by cpu)
|
long |
compareAndSet8ByteAlignment()
Returns the amount of alignment needed for addresses to do 8 byte atomic operations on (if supported by cpu)
|
boolean |
compareAndSetByte(long offset,
byte expect,
byte update) |
boolean |
compareAndSetInt(long offset,
int expect,
int update) |
boolean |
compareAndSetLong(long offset,
long expect,
long update) |
boolean |
compareAndSetShort(long offset,
short expect,
short update) |
byte |
getAndAdd(long offset,
byte aByte)
adds the parameter to the byte at offset. returns the previous value. this operation is atomic.
|
int |
getAndAdd(long offset,
int aInt)
adds the parameter to the int at offset. returns the previous value. this operation is atomic.
|
long |
getAndAdd(long offset,
long aLong)
adds the parameter to the long at offset. returns the previous value. this operation is atomic.
|
short |
getAndAdd(long offset,
short aShort)
adds the parameter to the short at offset. returns the previous value. this operation is atomic.
|
byte |
getAndAddByte(long offset,
byte aByte) |
int |
getAndAddInt(long offset,
int aInt) |
long |
getAndAddLong(long offset,
long aLong) |
short |
getAndAddShort(long offset,
short aShort) |
byte |
getAndSet(long offset,
byte aByte)
sets the value at offset to the given byte. returns the previous value. this operation is atomic.
|
int |
getAndSet(long offset,
int aInt)
sets the value at offset to the given int. returns the previous value. this operation is atomic.
|
long |
getAndSet(long offset,
long aLong)
sets the value at offset to the given long. returns the previous value. this operation is atomic.
|
short |
getAndSet(long offset,
short aShort)
sets the value at offset to the given short. returns the previous value. this operation is atomic.
|
byte |
getAndSetByte(long offset,
byte aByte) |
int |
getAndSetInt(long offset,
int aInt) |
long |
getAndSetLong(long offset,
long aLong) |
short |
getAndSetShort(long offset,
short aShort) |
long |
getNativePointer()
returns the native pointer assosicated with this memory.
|
long |
getNativePointer(long off)
returns the native pointer to the given offset.
|
long |
indexOf(long offset,
byte value)
Returns the next offset in the memory that has the given value.
|
boolean |
isValid()
Returns true if the close() method of this memory has not yet been called.
|
boolean |
isValid(long off)
Returns true if the close() method of this memory has not yet been called and the memory is valid for the given offset (at least 1 byte can be read/written at the given offset)
|
boolean |
isValid(long off,
long len)
Returns true if the close() method of this memory has not yet been called and the memory is valid for the given offset and length
|
byte |
read(long offset)
read 1 byte from the offset address.
|
void |
read(long offset,
byte[] buffer)
reads buffer.length bytes from the offset address and stores them into the buffer starting at offset 0.
|
void |
read(long offset,
byte[] buffer,
int bufferOffset,
int len)
reads len bytes from the offset address and stores them into the buffer starting at bufferOffset.
|
void |
read(long offset,
byte[] bytes,
int size,
int off,
int len) |
void |
read(long offset,
ByteBuffer buffer,
int len)
reads len bytes from the offset address and stores them into the buffer.
|
void |
read(long offset,
char[] chars,
int size,
int off,
int len) |
void |
read(long offset,
double[] doubles,
int off,
int len) |
void |
read(long offset,
float[] floats,
int off,
int len) |
void |
read(long offset,
int[] ints,
int size,
int off,
int len) |
void |
read(long offset,
long[] longs,
int size,
int off,
int len) |
void |
read(long off,
NativeMemory dst,
long dstOff,
long len)
reads len bytes from offset address and stores them into dst.
|
void |
read(long offset,
short[] shorts,
int size,
int off,
int len) |
double |
readDouble(long offset)
read 8 bytes from the offset address.
|
float |
readFloat(long offset)
read 4 bytes from the offset address.
|
int |
readInt(long offset)
read 4 bytes from the offset address.
|
int |
readIntBE(long offset)
read 4 bytes from the offset address and assume whatever value was read is big endian.
|
int |
readIntLE(long offset)
read 4 bytes from the offset address and assume whatever value was read is big endian.
|
long |
readLong(long offset)
read 8 bytes from the offset address.
|
long |
readLongBE(long offset) |
long |
readLongLE(long offset) |
long |
readPointer(long offset)
read a pointer from the given offset.
|
short |
readShort(long offset)
read 2 bytes from the offset address.
|
short |
readShortBE(long offset) |
short |
readShortLE(long offset) |
int |
readUnsignedByte(long offset)
read 1 byte from the offset address and read it as a unsigned byte.
|
long |
readUnsignedInt(long offset)
read 4 bytes from the offset address.
|
long |
readUnsignedIntBE(long offset) |
long |
readUnsignedIntLE(long offset) |
int |
readUnsignedShort(long offset)
reads 2 bytes from the offset address and treats them as a unsigned short.
|
int |
readUnsignedShortBE(long offset) |
int |
readUnsignedShortLE(long offset) |
int |
readUntilByte(long offset,
byte value,
byte[] buffer,
int off,
int len)
reads bytes into a buffer until a byte is encountered that is equal to the value parameter.
|
long |
remaining(long off)
returns the amount of bytes remaining to be read/written to until the end of the memory is reached.
|
void |
set(long offset,
byte value,
long len) |
void |
set(long offset,
int value,
long len)
Writes len bytes with the given value to the offset.
|
long |
size()
returns the size of this memory.
|
boolean |
spin(long offset,
byte expect,
long aSpinTime,
long aTimeout,
TimeUnit aUnit)
returns true if the value at offset becomes expected.
|
void |
spin(long offset,
byte expect,
long aSpinTime,
TimeUnit aUnit)
returns true if the value at offset becomes expected.
|
boolean |
spin(long offset,
int expect,
long aSpinTime,
long aTimeout,
TimeUnit aUnit)
returns true if the value at offset becomes expected.
|
void |
spin(long offset,
int expect,
long aSpinTime,
TimeUnit aUnit)
returns true if the value at offset becomes expected.
|
boolean |
spin(long offset,
long expect,
long aSpinTime,
long aTimeout,
TimeUnit aUnit)
returns true if the value at offset becomes expected.
|
void |
spin(long offset,
long expect,
long aSpinTime,
TimeUnit aUnit)
returns true if the value at offset becomes expected.
|
boolean |
spin(long offset,
short expect,
long aSpinTime,
long aTimeout,
TimeUnit aUnit)
returns true if the value at offset becomes expected.
|
void |
spin(long offset,
short expect,
long aSpinTime,
TimeUnit aUnit)
returns true if the value at offset becomes expected.
|
boolean |
spinAndSet(long offset,
byte expect,
byte update,
long aSpinTime,
long aTimeout,
TimeUnit aUnit)
sets the value to update if it ever becomes expect before aTimeout elapses. returns true if the value was write false if the timeout expired.
|
void |
spinAndSet(long offset,
byte expect,
byte update,
long aSpinTime,
TimeUnit aUnit)
sets the value to update if it ever becomes expect before aTimeout elapses. returns true if the value was write false if the timeout expired.
|
boolean |
spinAndSet(long offset,
int expect,
int update,
long aSpinTime,
long aTimeout,
TimeUnit aUnit)
sets the value to update if it ever becomes expect before aTimeout elapses. returns true if the value was written false if the timeout expired.
|
void |
spinAndSet(long offset,
int expect,
int update,
long aSpinTime,
TimeUnit aUnit)
sets the value to update if it ever becomes expect before aTimeout elapses. returns true if the value was write false if the timeout expired.
|
boolean |
spinAndSet(long offset,
long expect,
long update,
long aSpinTime,
long aTimeout,
TimeUnit aUnit)
sets the value to update if it ever becomes expect before aTimeout elapses. returns true if the value was written false if the timeout expired.
|
void |
spinAndSet(long offset,
long expect,
long update,
long aSpinTime,
TimeUnit aUnit)
sets the value to update if it ever becomes expect before aTimeout elapses. returns true if the value was write false if the timeout expired.
|
boolean |
spinAndSet(long offset,
short expect,
short update,
long aSpinTime,
long aTimeout,
TimeUnit aUnit)
sets the value to update if it ever becomes expect before aTimeout elapses. returns true if the value was written false if the timeout expired.
|
void |
spinAndSet(long offset,
short expect,
short update,
long aSpinTime,
TimeUnit aUnit)
sets the value to update if it ever becomes expect before aTimeout elapses. returns true if the value was write false if the timeout expired.
|
void |
stopSpin()
Stops/Cancels all java calls that are inside the spin(...) methods.
|
NativeBuffer |
stream()
Creates a new NativeBuffer instance that can be used to read this memory as one would read a InputStream
Every instance of NativeBuffer is completely independent (other than all of them accessing this memory object)
Note: the returned object must not be used by multiple threads at once.
|
NativeBuffer |
stream(long offset) |
boolean |
supportsCompareAndSet16Byte() |
boolean |
supportsCompareAndSet1Byte()
Returns true if the cpu can do 1 byte atomic operations.
|
boolean |
supportsCompareAndSet2Byte()
Returns the amount of alignment needed for addresses to do 2 byte atomic operations on (if supported by cpu)
|
boolean |
supportsCompareAndSet4Byte()
Returns true if the cpu can do 4 byte atomic operations.
|
boolean |
supportsCompareAndSet8Byte()
Returns true if the cpu can do 8 byte atomic operations.
|
void |
sync(long offset,
long length,
boolean invalidate)
Synchronize the changes made to the memory to the device/file backing the memory.
|
void |
write(long offset,
byte aByte)
writes a single byte to the offset address.
|
void |
write(long offset,
byte[] buffer)
writes all bytes from the buffer to the offset address in the shared memory.
|
void |
write(long offset,
byte[] buffer,
int bufferOffset,
int len)
writes len bytes starting from the index bufferOffset from the buffer to the offset address in the shared memory.
|
void |
write(long offset,
byte[] bytes,
int size,
int off,
int len)
Writes the byte[] to the memory.
|
void |
write(long offset,
ByteBuffer buffer,
int len)
writes len bytes to the offset address from the buffer.
|
void |
write(long offset,
char[] chars,
int size,
int off,
int len)
Writes the char[] to the memory.
|
void |
write(long offset,
double aDouble)
writes 8 bytes to the offset address.
|
void |
write(long offset,
double[] doubles,
int off,
int len)
Writes the double[] to memory using 8 bytes per float.
|
void |
write(long offset,
float aFloat)
writes 4 bytes to the offset address.
|
void |
write(long offset,
float[] floats,
int off,
int len)
Writes the float[] to memory using 4 bytes per float.
|
void |
write(long offset,
int aInt)
writes 4 bytes to the offset address.
|
void |
write(long offset,
int[] ints,
int size,
int off,
int len)
Writes the int[] to the memory.
|
void |
write(long offset,
long aLong)
writes 8 bytes to the offset address.
|
void |
write(long offset,
long[] longs,
int size,
int off,
int len)
Writes the long[] to the memory.
|
void |
write(long offset,
short aShort)
writes 2 bytes to the offset address.
|
void |
write(long offset,
short[] shorts,
int size,
int off,
int len)
Writes the short[] to the memory.
|
void |
writeByte(long offset,
byte aByte)
writes a single byte to the offset address.
|
void |
writeByte(long offset,
int aInt) |
void |
writeDouble(long offset,
double aDouble)
writes 8 bytes to the offset address.
|
void |
writeFloat(long offset,
float aFloat)
writes 4 bytes to the offset address.
|
void |
writeInt(long offset,
int aInt)
writes 4 bytes to the offset address.
|
void |
writeIntBE(long offset,
int aInt) |
void |
writeIntLE(long offset,
int aInt) |
void |
writeLong(long offset,
long aLong)
writes 8 bytes to the offset address.
|
void |
writeLongBE(long offset,
long aLong) |
void |
writeLongLE(long offset,
long aLong) |
void |
writePointer(long offset,
long ptr)
writes a pointer value to the given offset.
|
void |
writeShort(long offset,
int aShort)
writes 2 bytes to the offset address.
|
void |
writeShort(long offset,
short aShort)
writes 2 bytes to the offset address.
|
void |
writeShortBE(long offset,
int aShort) |
void |
writeShortBE(long offset,
short aShort) |
void |
writeShortLE(long offset,
int aShort) |
void |
writeShortLE(long offset,
short aShort) |
void |
zero()
Sets the entire memory to 0.
|
void close()
close in interface AutoCloseableboolean isValid()
boolean isValid(long off)
boolean isValid(long off,
long len)
long size()
long remaining(long off)
off - must be greater or equal to zerolong getNativePointer()
long getNativePointer(long off)
void sync(long offset,
long length,
boolean invalidate)
throws SyncFailedException
LinuxNativeUtil.getpagesize()).
This change is always guaranteed to contain the entirety of the requested area.invalidate - if true invalidate other mappings of the same device/file so that they reflect the changes.SyncFailedException - if invalidate was true and another mapping has a memory lock on the region to be invalidated.void set(long offset,
byte value,
long len)
void set(long offset,
int value,
long len)
void zero()
void write(long offset,
byte[] buffer,
int bufferOffset,
int len)
void write(long offset,
byte[] buffer)
void write(long offset,
ByteBuffer buffer,
int len)
void write(long offset,
byte[] bytes,
int size,
int off,
int len)
size - parameter controls how many bytes are used per index of the array.
size = 1 would just write the byte[] as is
size = 2 would write a '0' byte followed by the byte
size = 3 would write 2 '0' bytes followed by the char
...void read(long offset,
byte[] bytes,
int size,
int off,
int len)
void write(long offset,
char[] chars,
int size,
int off,
int len)
size - parameter controls how many bytes are used per index of the array.
size = 1 would first cast each char to a byte.
size = 3 would write a 0 byte followed by the char
size = 4 would write 2 0 bytes followed by the char
...void read(long offset,
char[] chars,
int size,
int off,
int len)
void write(long offset,
short[] shorts,
int size,
int off,
int len)
size - parameter controls how many bytes are used per index of the array.
size = 1 would first cast each short to a byte.
size = 3 would write a 0 byte followed by the short
size = 4 would write 2 0 bytes followed by the short
...void read(long offset,
short[] shorts,
int size,
int off,
int len)
void write(long offset,
int[] ints,
int size,
int off,
int len)
size - parameter controls how many bytes are used per index of the array.
size = 1 would first cast each int to a byte.
...
size = 3 would write the 24 least significant bits as 3 bytes.
size = 4 would write the int[] as is
...
size = 5 would prefix each int with a 0 byte
* ...void read(long offset,
int[] ints,
int size,
int off,
int len)
void write(long offset,
long[] longs,
int size,
int off,
int len)
size - parameter controls how many bytes are used per index of the array.
size = 1 would first cast each long to a byte.
...
size = 3 would write the 24 least significant bits as 3 bytes.
size = 4 would write each long to a int.
...
size = 9 would prefix each long with a 0 byte
* ...void read(long offset,
long[] longs,
int size,
int off,
int len)
void write(long offset,
float[] floats,
int off,
int len)
void read(long offset,
float[] floats,
int off,
int len)
void write(long offset,
double[] doubles,
int off,
int len)
void read(long offset,
double[] doubles,
int off,
int len)
void write(long offset,
byte aByte)
void writeByte(long offset,
byte aByte)
void writeByte(long offset,
int aInt)
void writePointer(long offset,
long ptr)
void write(long offset,
int aInt)
void writeInt(long offset,
int aInt)
void writeIntBE(long offset,
int aInt)
void writeIntLE(long offset,
int aInt)
void write(long offset,
long aLong)
void writeLong(long offset,
long aLong)
void writeLongBE(long offset,
long aLong)
void writeLongLE(long offset,
long aLong)
void write(long offset,
float aFloat)
void writeFloat(long offset,
float aFloat)
void write(long offset,
double aDouble)
void writeDouble(long offset,
double aDouble)
void write(long offset,
short aShort)
void writeShort(long offset,
short aShort)
void writeShort(long offset,
int aShort)
void writeShortBE(long offset,
int aShort)
void writeShortLE(long offset,
int aShort)
void writeShortBE(long offset,
short aShort)
void writeShortLE(long offset,
short aShort)
void read(long offset,
byte[] buffer,
int bufferOffset,
int len)
void read(long offset,
byte[] buffer)
void read(long off,
NativeMemory dst,
long dstOff,
long len)
void read(long offset,
ByteBuffer buffer,
int len)
int readInt(long offset)
int readIntBE(long offset)
int readIntLE(long offset)
long readUnsignedInt(long offset)
long readUnsignedIntBE(long offset)
long readUnsignedIntLE(long offset)
long readLong(long offset)
long readLongBE(long offset)
long readLongLE(long offset)
long readPointer(long offset)
float readFloat(long offset)
double readDouble(long offset)
short readShort(long offset)
short readShortBE(long offset)
short readShortLE(long offset)
int readUnsignedShort(long offset)
int readUnsignedShortBE(long offset)
int readUnsignedShortLE(long offset)
byte read(long offset)
int readUnsignedByte(long offset)
long getAndAdd(long offset,
long aLong)
long getAndAddLong(long offset,
long aLong)
int getAndAdd(long offset,
int aInt)
int getAndAddInt(long offset,
int aInt)
short getAndAdd(long offset,
short aShort)
short getAndAddShort(long offset,
short aShort)
byte getAndAdd(long offset,
byte aByte)
byte getAndAddByte(long offset,
byte aByte)
long getAndSet(long offset,
long aLong)
long getAndSetLong(long offset,
long aLong)
int getAndSet(long offset,
int aInt)
int getAndSetInt(long offset,
int aInt)
short getAndSet(long offset,
short aShort)
short getAndSetShort(long offset,
short aShort)
byte getAndSet(long offset,
byte aByte)
byte getAndSetByte(long offset,
byte aByte)
boolean compareAndSet(long offset,
long expect,
long update)
boolean compareAndSetLong(long offset,
long expect,
long update)
boolean supportsCompareAndSet8Byte()
long compareAndSet8ByteAlignment()
boolean compareAndSet(long offset,
int expect,
int update)
boolean compareAndSetInt(long offset,
int expect,
int update)
boolean supportsCompareAndSet4Byte()
long compareAndSet4ByteAlignment()
boolean compareAndSet(long offset,
short expect,
short update)
boolean compareAndSetShort(long offset,
short expect,
short update)
boolean supportsCompareAndSet2Byte()
long compareAndSet2ByteAlignment()
boolean compareAndSet(long offset,
byte expect,
byte update)
boolean compareAndSetByte(long offset,
byte expect,
byte update)
boolean supportsCompareAndSet1Byte()
long compareAndSet1ByteAlignment()
void stopSpin()
boolean spinAndSet(long offset,
long expect,
long update,
long aSpinTime,
long aTimeout,
TimeUnit aUnit)
boolean spinAndSet(long offset,
int expect,
int update,
long aSpinTime,
long aTimeout,
TimeUnit aUnit)
boolean spinAndSet(long offset,
short expect,
short update,
long aSpinTime,
long aTimeout,
TimeUnit aUnit)
boolean spinAndSet(long offset,
byte expect,
byte update,
long aSpinTime,
long aTimeout,
TimeUnit aUnit)
void spinAndSet(long offset,
long expect,
long update,
long aSpinTime,
TimeUnit aUnit)
void spinAndSet(long offset,
int expect,
int update,
long aSpinTime,
TimeUnit aUnit)
void spinAndSet(long offset,
short expect,
short update,
long aSpinTime,
TimeUnit aUnit)
void spinAndSet(long offset,
byte expect,
byte update,
long aSpinTime,
TimeUnit aUnit)
boolean spin(long offset,
long expect,
long aSpinTime,
long aTimeout,
TimeUnit aUnit)
boolean spin(long offset,
int expect,
long aSpinTime,
long aTimeout,
TimeUnit aUnit)
boolean spin(long offset,
short expect,
long aSpinTime,
long aTimeout,
TimeUnit aUnit)
boolean spin(long offset,
byte expect,
long aSpinTime,
long aTimeout,
TimeUnit aUnit)
void spin(long offset,
long expect,
long aSpinTime,
TimeUnit aUnit)
void spin(long offset,
int expect,
long aSpinTime,
TimeUnit aUnit)
void spin(long offset,
short expect,
long aSpinTime,
TimeUnit aUnit)
void spin(long offset,
byte expect,
long aSpinTime,
TimeUnit aUnit)
boolean supportsCompareAndSet16Byte()
long compareAndSet16ByteAlignment()
boolean compareAndSet(long offset,
byte[] data)
long indexOf(long offset,
byte value)
int readUntilByte(long offset,
byte value,
byte[] buffer,
int off,
int len)
len - for optimal performance a value <= 512 is recommended.offset - this method permits offsets beyond the memory size. The method will just return 0 in those cases.NativeBuffer stream()
NativeBuffer stream(long offset)
Copyright © 2024. All rights reserved.