public interface LowLevelBuffer
Modifier and Type | Method and Description |
---|---|
long |
allocate(long len)
Allocate the given number of bytes as a new memory block and return the 64-bit address.
|
void |
cleanup()
Deallocate all memory allocations which have not been deallocated explicitly previously.
|
int |
compiledWordSize()
Returns the word size (the size of a pointer) for the native code as compiled.
|
void |
copy(long source,
long dest,
long offset,
long len)
Copy the specified range of contents from the source memory block to the destination memory
block.
|
boolean |
deallocate(long addr)
De-allocate the memory block at the given 64-bit address.
|
long |
findNextNull(long addr,
long idx,
long size)
Returns the next index position into the array which is the
null byte, starting
at the given index position. |
void |
incrementReference(long addr)
Increments the number of references to this memory.
|
boolean |
isLittleEndian()
Reports on the native byte-ordering of the platform on which this library is
running.
|
byte[] |
read(long addr,
long offset,
long len)
Read the specified range of contents from the memory block at the given 64-bit address.
|
void |
write(long addr,
long offset,
byte[] data)
Write the specified contents to the memory block at the given 64-bit address plus offset.
|
boolean isLittleEndian()
true
if the platform uses little-endian byte-ordering,
false
if the platform is big-endian.int compiledWordSize()
long allocate(long len)
To duplicate the permissiveness of the 4GL memptr allocation (where certain operations often can read or write past the end of the allocated buffer without an access violation), the buffer allocated by this function will always be 16 bytes larger than the requested size.
len
- The size in bytes of the memory region to allocate.long findNextNull(long addr, long idx, long size)
null
byte, starting
at the given index position.addr
- The 64-bit pointer to a memory region previously allocated using this module.
DO NOT pass in an invalid pointer.idx
- The index position at which to start the search.size
- The length of the buffer. If the search reaches this byte without finding a
null byte, then this value will be returned. If this is given as -1, then the
caller has no size information and we operate in unsafe mode. In this mode
the code will read until it finds a null
or gets an access
violation. This is how the 4GL does it too.null
byte or
the length of the array if no null
byte is contained.boolean deallocate(long addr)
true
, the memory in this region MUST NOT be accessed after this call.addr
- The 64-bit pointer to a memory region previously allocated using this module.
DO NOT pass in an invalid pointer. DO NOT deallocate the same pointer after this
method returned true
.true
if the memory was deallocated and false
if the deallocation
failed because this memory zone was shared with other variable. If so then the
counter was decremented and the memory will be released when it reaches zero.void incrementReference(long addr)
deallocate(long)
. It will automatically decrement the counter and truly
deallocate the memory when it reaches 0.addr
- The 64-bit pointer to a memory region previously allocated using this module.
DO NOT pass in an invalid pointer.byte[] read(long addr, long offset, long len)
addr
- The 64-bit pointer to a memory region previously allocated using this module.
DO NOT pass in an invalid pointer.offset
- The 0-based index position from the beginning of the buffer, from which to start
reading.len
- The number of bytes to read. Must be greater than 0 and must NOT extend past the
end of the buffer.null
if there is any problem allocating
the array.void write(long addr, long offset, byte[] data)
addr
- The 64-bit pointer to a memory region previously allocated using this module.
DO NOT pass in an invalid pointer.offset
- The 0-based index position from the beginning of the buffer, at which to start
writing.data
- The bytes to write. The entire contents of the array will be written. The length
of the array must not be bigger than the number of bytes between the offset and
the end of the buffer.void copy(long source, long dest, long offset, long len)
source
- The 64-bit pointer to a memory region previously allocated using this module.
DO NOT pass in an invalid pointer.dest
- The 64-bit pointer to a memory region previously allocated using this module.
DO NOT pass in an invalid pointer.offset
- The 0-based index position from the beginning of the buffer, at which to start
writing.len
- The number of bytes to write. Must be greater than 0 and must NOT extend past the
end of the destination buffer.void cleanup()