Class MemoryUtil
- java.lang.Object
-
- org.lwjgl.system.MemoryUtil
-
public final class MemoryUtil extends java.lang.ObjectThis class provides functionality for managing native memory.All methods in this class will make use of
Unsafeif it's available, for performance. If Unsafe is not available, the fallback implementations make use of reflection and, in the worst-case, JNI.Method names in this class are prefixed with
memto avoid ambiguities when used with static imports.Text encoding/decoding
Three codecs are available, each with a different postfix:- UTF16 - Direct mapping of 2 bytes to Java char and vice versa
- UTF8 - custom UTF-8 codec without intermediate allocations
- ASCII - Not the original 7bit ASCII, but any character set with a single byte encoding (ISO 8859-1, Windows-1252, etc.)
Methods in bindings that accept/return
CharSequence/Stringalso supportByteBuffer, so custom codecs can be used if necessary.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceMemoryUtil.MemoryAllocationReportThe memory allocation report callback.static interfaceMemoryUtil.MemoryAllocatorThe interface implemented by the memory allocator used by the explicit memory management API (memAlloc(int),memFree(java.nio.Buffer), etc).
-
Field Summary
Fields Modifier and Type Field Description static intCACHE_LINE_SIZEThe cache-line size, in bytes.static longNULLAlias for the null pointer address.static intPAGE_SIZEThe memory page size, in bytes.
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static MemoryUtil.MemoryAllocatorgetAllocator()Returns theMemoryUtil.MemoryAllocatorinstance used internally by the explicit memory management API (memAlloc(int),memFree(java.nio.Buffer), etc).static MemoryUtil.MemoryAllocatorgetAllocator(boolean tracked)Returns theMemoryUtil.MemoryAllocatorinstance used internally by the explicit memory management API (memAlloc(int),memFree(java.nio.Buffer), etc).static longmemAddress(java.nio.Buffer buffer)Polymorphic version ofmemAddress(ByteBuffer).static longmemAddress(java.nio.ByteBuffer buffer)Returns the memory address at the current position of the specified buffer.static longmemAddress(java.nio.ByteBuffer buffer, int position)Returns the memory address at the specified position of the specified buffer.static longmemAddress(java.nio.CharBuffer buffer)CharBuffer version ofmemAddress(ByteBuffer).static longmemAddress(java.nio.CharBuffer buffer, int position)CharBuffer version ofmemAddress(ByteBuffer, int).static longmemAddress(java.nio.DoubleBuffer buffer)DoubleBuffer version ofmemAddress(ByteBuffer).static longmemAddress(java.nio.DoubleBuffer buffer, int position)DoubleBuffer version ofmemAddress(ByteBuffer, int).static longmemAddress(java.nio.FloatBuffer buffer)FloatBuffer version ofmemAddress(ByteBuffer).static longmemAddress(java.nio.FloatBuffer buffer, int position)FloatBuffer version ofmemAddress(ByteBuffer, int).static longmemAddress(java.nio.IntBuffer buffer)IntBuffer version ofmemAddress(ByteBuffer).static longmemAddress(java.nio.IntBuffer buffer, int position)IntBuffer version ofmemAddress(ByteBuffer, int).static longmemAddress(java.nio.LongBuffer buffer)LongBuffer version ofmemAddress(ByteBuffer).static longmemAddress(java.nio.LongBuffer buffer, int position)LongBuffer version ofmemAddress(ByteBuffer, int).static longmemAddress(java.nio.ShortBuffer buffer)ShortBuffer version ofmemAddress(ByteBuffer).static longmemAddress(java.nio.ShortBuffer buffer, int position)ShortBuffer version ofmemAddress(ByteBuffer, int).static longmemAddress(CustomBuffer<?> buffer)CustomBuffer version ofmemAddress(ByteBuffer).static longmemAddress(CustomBuffer<?> buffer, int position)CustomBuffer version ofmemAddress(ByteBuffer, int).static longmemAddress0(java.nio.Buffer buffer)Returns the memory address of the specified buffer.static longmemAddressSafe(java.nio.ByteBuffer buffer)Null-safe version ofmemAddress(ByteBuffer).static longmemAddressSafe(java.nio.CharBuffer buffer)CharBuffer version ofmemAddressSafe(ByteBuffer).static longmemAddressSafe(java.nio.DoubleBuffer buffer)DoubleBuffer version ofmemAddressSafe(ByteBuffer).static longmemAddressSafe(java.nio.FloatBuffer buffer)FloatBuffer version ofmemAddressSafe(ByteBuffer).static longmemAddressSafe(java.nio.IntBuffer buffer)IntBuffer version ofmemAddressSafe(ByteBuffer).static longmemAddressSafe(java.nio.LongBuffer buffer)LongBuffer version ofmemAddressSafe(ByteBuffer).static longmemAddressSafe(java.nio.ShortBuffer buffer)ShortBuffer version ofmemAddressSafe(ByteBuffer).static longmemAddressSafe(Pointer pointer)Pointer version ofmemAddressSafe(ByteBuffer).static java.nio.ByteBuffermemAlignedAlloc(int alignment, int size)The standard C aligned_alloc function.static voidmemAlignedFree(java.nio.ByteBuffer ptr)Frees a block of memory that was allocated withmemAlignedAlloc(int, int).static java.nio.ByteBuffermemAlloc(int size)The standard C malloc function.static CLongBuffermemAllocCLong(int size)CLongBufferversion ofmemAlloc(int).static java.nio.DoubleBuffermemAllocDouble(int size)DoubleBuffer version ofmemAlloc(int).static java.nio.FloatBuffermemAllocFloat(int size)FloatBuffer version ofmemAlloc(int).static java.nio.IntBuffermemAllocInt(int size)IntBuffer version ofmemAlloc(int).static java.nio.LongBuffermemAllocLong(int size)LongBuffer version ofmemAlloc(int).static PointerBuffermemAllocPointer(int size)PointerBuffer version ofmemAlloc(int).static java.nio.ShortBuffermemAllocShort(int size)ShortBuffer version ofmemAlloc(int).static java.lang.StringmemASCII(long address)Converts the null-terminated ASCII encoded string at the specified memory address to aString.static java.lang.StringmemASCII(long address, int length)Converts the ASCII encoded string at the specified memory address to aString.static java.nio.ByteBuffermemASCII(java.lang.CharSequence text)Returns a ByteBuffer containing the specified text ASCII encoded and null-terminated.static java.nio.ByteBuffermemASCII(java.lang.CharSequence text, boolean nullTerminated)Returns a ByteBuffer containing the specified text ASCII encoded and optionally null-terminated.static intmemASCII(java.lang.CharSequence text, boolean nullTerminated, java.nio.ByteBuffer target)Encodes and optionally null-terminates the specified text using ASCII encoding.static intmemASCII(java.lang.CharSequence text, boolean nullTerminated, java.nio.ByteBuffer target, int offset)Encodes and optionally null-terminates the specified text using ASCII encoding.static java.lang.StringmemASCII(java.nio.ByteBuffer buffer)Decodes the bytes with index[position(), position()+remaining()) inbuffer, as an ASCII string.static java.lang.StringmemASCII(java.nio.ByteBuffer buffer, int length)Decodes the bytes with index[position(), position()+length) inbuffer, as an ASCII string.static java.lang.StringmemASCII(java.nio.ByteBuffer buffer, int length, int offset)Decodes the bytes with index[offset, offset+length) inbuffer, as an ASCII string.static java.lang.StringmemASCIISafe(long address)static java.lang.StringmemASCIISafe(long address, int length)static java.nio.ByteBuffermemASCIISafe(java.lang.CharSequence text)static java.nio.ByteBuffermemASCIISafe(java.lang.CharSequence text, boolean nullTerminated)static java.lang.StringmemASCIISafe(java.nio.ByteBuffer buffer)static java.nio.ByteBuffermemByteBuffer(long address, int capacity)Creates a new direct ByteBuffer that starts at the specified memory address and has the specified capacity.static java.nio.ByteBuffermemByteBuffer(java.nio.CharBuffer buffer)Creates aByteBufferinstance as a view of the specifiedCharBufferbetween its current position and limit.static java.nio.ByteBuffermemByteBuffer(java.nio.DoubleBuffer buffer)Creates aByteBufferinstance as a view of the specifiedDoubleBufferbetween its current position and limit.static java.nio.ByteBuffermemByteBuffer(java.nio.FloatBuffer buffer)Creates aByteBufferinstance as a view of the specifiedFloatBufferbetween its current position and limit.static java.nio.ByteBuffermemByteBuffer(java.nio.IntBuffer buffer)Creates aByteBufferinstance as a view of the specifiedIntBufferbetween its current position and limit.static java.nio.ByteBuffermemByteBuffer(java.nio.LongBuffer buffer)Creates aByteBufferinstance as a view of the specifiedLongBufferbetween its current position and limit.static java.nio.ByteBuffermemByteBuffer(java.nio.ShortBuffer buffer)Creates aByteBufferinstance as a view of the specifiedShortBufferbetween its current position and limit.static java.nio.ByteBuffermemByteBuffer(CustomBuffer<?> buffer)Creates aByteBufferinstance as a view of the specifiedCustomBufferbetween its current position and limit.static java.nio.ByteBuffermemByteBufferNT1(long address)Creates a new direct ByteBuffer that starts at the specified memory address and has capacity equal to the null-terminated string starting at that address.static java.nio.ByteBuffermemByteBufferNT1(long address, int maxLength)Creates a new direct ByteBuffer that starts at the specified memory address and has capacity equal to the null-terminated string starting at that address, up to a maximum ofmaxLengthbytes.static java.nio.ByteBuffermemByteBufferNT1Safe(long address)static java.nio.ByteBuffermemByteBufferNT1Safe(long address, int maxLength)static java.nio.ByteBuffermemByteBufferNT2(long address)Creates a new direct ByteBuffer that starts at the specified memory address and has capacity equal to the null-terminated string starting at that address.static java.nio.ByteBuffermemByteBufferNT2(long address, int maxLength)Creates a new direct ByteBuffer that starts at the specified memory address and has capacity equal to the null-terminated string starting at that address, up to a maximum ofmaxLengthbytes.static java.nio.ByteBuffermemByteBufferNT2Safe(long address)static java.nio.ByteBuffermemByteBufferNT2Safe(long address, int maxLength)static java.nio.ByteBuffermemByteBufferSafe(long address, int capacity)static java.nio.ByteBuffermemCalloc(int num)Alternative version ofmemCalloc(int, int).static java.nio.ByteBuffermemCalloc(int num, int size)The standard C calloc function.static CLongBuffermemCallocCLong(int num)CLongBufferversion ofmemCalloc(int, int).static java.nio.DoubleBuffermemCallocDouble(int num)DoubleBuffer version ofmemCalloc(int, int).static java.nio.FloatBuffermemCallocFloat(int num)FloatBuffer version ofmemCalloc(int, int).static java.nio.IntBuffermemCallocInt(int num)IntBuffer version ofmemCalloc(int, int).static java.nio.LongBuffermemCallocLong(int num)LongBuffer version ofmemCalloc(int, int).static PointerBuffermemCallocPointer(int num)PointerBuffer version ofmemCalloc(int, int).static java.nio.ShortBuffermemCallocShort(int num)ShortBuffer version ofmemCalloc(int, int).static java.nio.CharBuffermemCharBuffer(long address, int capacity)Creates a new direct CharBuffer that starts at the specified memory address and has the specified capacity.static java.nio.CharBuffermemCharBufferSafe(long address, int capacity)static CLongBuffermemCLongBuffer(long address, int capacity)Creates a new directCLongBufferthat starts at the specified memory address and has the specified capacity.static CLongBuffermemCLongBufferSafe(long address, int capacity)static voidmemCopy(long src, long dst, long bytes)Sets all bytes in a specified block of memory to a copy of another block.static voidmemCopy(java.nio.ByteBuffer src, java.nio.ByteBuffer dst)Sets all bytes in a specified block of memory to a copy of another block.static voidmemCopy(java.nio.CharBuffer src, java.nio.CharBuffer dst)Sets all bytes in a specified block of memory to a copy of another block.static voidmemCopy(java.nio.DoubleBuffer src, java.nio.DoubleBuffer dst)Sets all bytes in a specified block of memory to a copy of another block.static voidmemCopy(java.nio.FloatBuffer src, java.nio.FloatBuffer dst)Sets all bytes in a specified block of memory to a copy of another block.static voidmemCopy(java.nio.IntBuffer src, java.nio.IntBuffer dst)Sets all bytes in a specified block of memory to a copy of another block.static voidmemCopy(java.nio.LongBuffer src, java.nio.LongBuffer dst)Sets all bytes in a specified block of memory to a copy of another block.static voidmemCopy(java.nio.ShortBuffer src, java.nio.ShortBuffer dst)Sets all bytes in a specified block of memory to a copy of another block.static <T extends CustomBuffer<T>>
voidmemCopy(T src, T dst)Sets all bytes in a specified block of memory to a copy of another block.static voidmemDeleteGlobalRef(long globalRef)Deprecated.static voidmemDeleteWeakGlobalRef(long globalRef)Deprecated.static java.nio.DoubleBuffermemDoubleBuffer(long address, int capacity)Creates a new direct DoubleBuffer that starts at the specified memory address and has the specified capacity.static java.nio.DoubleBuffermemDoubleBufferSafe(long address, int capacity)static java.nio.ByteBuffermemDuplicate(java.nio.ByteBuffer buffer)Duplicates the specified buffer.static java.nio.CharBuffermemDuplicate(java.nio.CharBuffer buffer)Duplicates the specified buffer.static java.nio.DoubleBuffermemDuplicate(java.nio.DoubleBuffer buffer)Duplicates the specified buffer.static java.nio.FloatBuffermemDuplicate(java.nio.FloatBuffer buffer)Duplicates the specified buffer.static java.nio.IntBuffermemDuplicate(java.nio.IntBuffer buffer)Duplicates the specified buffer.static java.nio.LongBuffermemDuplicate(java.nio.LongBuffer buffer)Duplicates the specified buffer.static java.nio.ShortBuffermemDuplicate(java.nio.ShortBuffer buffer)Duplicates the specified buffer.static java.nio.FloatBuffermemFloatBuffer(long address, int capacity)Creates a new direct FloatBuffer that starts at the specified memory address and has the specified capacity.static java.nio.FloatBuffermemFloatBufferSafe(long address, int capacity)static voidmemFree(java.nio.Buffer ptr)The standard C free function.static voidmemFree(CustomBuffer ptr)CustomBufferversion ofmemFree(java.nio.Buffer).static longmemGetAddress(long ptr)static booleanmemGetBoolean(long ptr)static bytememGetByte(long ptr)static longmemGetCLong(long ptr)static doublememGetDouble(long ptr)static floatmemGetFloat(long ptr)static intmemGetInt(long ptr)static longmemGetLong(long ptr)static shortmemGetShort(long ptr)static <T> TmemGlobalRefToObject(long globalRef)Returns the object that the specified global reference points to.static java.nio.IntBuffermemIntBuffer(long address, int capacity)Creates a new direct IntBuffer that starts at the specified memory address and has the specified capacity.static java.nio.IntBuffermemIntBufferSafe(long address, int capacity)static intmemLengthASCII(java.lang.CharSequence value, boolean nullTerminated)Returns the number of bytes required to encode the specified text in the ASCII encoding.static intmemLengthNT1(java.nio.ByteBuffer buffer)Calculates the length, in bytes, of the null-terminated string that starts at the current position of the specified buffer.static intmemLengthNT2(java.nio.ByteBuffer buffer)Calculates the length, in bytes, of the null-terminated string that starts at the current position of the specified buffer.static intmemLengthUTF16(java.lang.CharSequence value, boolean nullTerminated)Returns the number of bytes required to encode the specified text in the UTF-16 encoding.static intmemLengthUTF8(java.lang.CharSequence value, boolean nullTerminated)Returns the number of bytes required to encode the specified text in the UTF-8 encoding.static java.nio.LongBuffermemLongBuffer(long address, int capacity)Creates a new direct LongBuffer that starts at the specified memory address and has the specified capacity.static java.nio.LongBuffermemLongBufferSafe(long address, int capacity)static longmemNewGlobalRef(java.lang.Object obj)Deprecated.static longmemNewWeakGlobalRef(java.lang.Object obj)Deprecated.static PointerBuffermemPointerBuffer(long address, int capacity)Creates a new PointerBuffer that starts at the specified memory address and has the specified capacity.static PointerBuffermemPointerBufferSafe(long address, int capacity)static voidmemPutAddress(long ptr, long value)static voidmemPutByte(long ptr, byte value)static voidmemPutCLong(long ptr, long value)static voidmemPutDouble(long ptr, double value)static voidmemPutFloat(long ptr, float value)static voidmemPutInt(long ptr, int value)static voidmemPutLong(long ptr, long value)static voidmemPutShort(long ptr, short value)static java.nio.ByteBuffermemRealloc(java.nio.ByteBuffer ptr, int size)The standard C realloc function.static java.nio.DoubleBuffermemRealloc(java.nio.DoubleBuffer ptr, int size)DoubleBuffer version ofmemRealloc(java.nio.ByteBuffer, int).static java.nio.FloatBuffermemRealloc(java.nio.FloatBuffer ptr, int size)FloatBuffer version ofmemRealloc(java.nio.ByteBuffer, int).static java.nio.IntBuffermemRealloc(java.nio.IntBuffer ptr, int size)IntBuffer version ofmemRealloc(java.nio.ByteBuffer, int).static java.nio.LongBuffermemRealloc(java.nio.LongBuffer ptr, int size)LongBuffer version ofmemRealloc(java.nio.ByteBuffer, int).static java.nio.ShortBuffermemRealloc(java.nio.ShortBuffer ptr, int size)ShortBuffer version ofmemRealloc(java.nio.ByteBuffer, int).static CLongBuffermemRealloc(CLongBuffer ptr, int size)CLongBufferversion ofmemRealloc(java.nio.ByteBuffer, int).static PointerBuffermemRealloc(PointerBuffer ptr, int size)PointerBuffer version ofmemRealloc(java.nio.ByteBuffer, int).static voidmemReport(MemoryUtil.MemoryAllocationReport report)Reports all live allocations.static voidmemReport(MemoryUtil.MemoryAllocationReport report, MemoryUtil.MemoryAllocationReport.Aggregate groupByStackTrace, boolean groupByThread)Reports aggregates for the live allocations.static voidmemSet(long ptr, int value, long bytes)Sets all bytes in a specified block of memory to a fixed value (usually zero).static voidmemSet(java.nio.ByteBuffer ptr, int value)Sets all bytes in a specified block of memory to a fixed value (usually zero).static voidmemSet(java.nio.CharBuffer ptr, int value)Sets all bytes in a specified block of memory to a fixed value (usually zero).static voidmemSet(java.nio.DoubleBuffer ptr, int value)Sets all bytes in a specified block of memory to a fixed value (usually zero).static voidmemSet(java.nio.FloatBuffer ptr, int value)Sets all bytes in a specified block of memory to a fixed value (usually zero).static voidmemSet(java.nio.IntBuffer ptr, int value)Sets all bytes in a specified block of memory to a fixed value (usually zero).static voidmemSet(java.nio.LongBuffer ptr, int value)Sets all bytes in a specified block of memory to a fixed value (usually zero).static voidmemSet(java.nio.ShortBuffer ptr, int value)Sets all bytes in a specified block of memory to a fixed value (usually zero).static <T extends CustomBuffer<T>>
voidmemSet(T ptr, int value)Sets all bytes in a specified block of memory to a fixed value (usually zero).static java.nio.ShortBuffermemShortBuffer(long address, int capacity)Creates a new direct ShortBuffer that starts at the specified memory address and has the specified capacity.static java.nio.ShortBuffermemShortBufferSafe(long address, int capacity)static java.nio.ByteBuffermemSlice(java.nio.ByteBuffer buffer)Slices the specified buffer.static java.nio.ByteBuffermemSlice(java.nio.ByteBuffer buffer, int offset, int capacity)Returns a slice of the specified buffer between(buffer.position() + offset)and(buffer.position() + offset + capacity).static java.nio.CharBuffermemSlice(java.nio.CharBuffer buffer)Slices the specified buffer.static java.nio.CharBuffermemSlice(java.nio.CharBuffer buffer, int offset, int capacity)Returns a slice of the specified buffer between(buffer.position() + offset)and(buffer.position() + offset + capacity).static java.nio.DoubleBuffermemSlice(java.nio.DoubleBuffer buffer)Slices the specified buffer.static java.nio.DoubleBuffermemSlice(java.nio.DoubleBuffer buffer, int offset, int capacity)Returns a slice of the specified buffer between(buffer.position() + offset)and(buffer.position() + offset + capacity).static java.nio.FloatBuffermemSlice(java.nio.FloatBuffer buffer)Slices the specified buffer.static java.nio.FloatBuffermemSlice(java.nio.FloatBuffer buffer, int offset, int capacity)Returns a slice of the specified buffer between(buffer.position() + offset)and(buffer.position() + offset + capacity).static java.nio.IntBuffermemSlice(java.nio.IntBuffer buffer)Slices the specified buffer.static java.nio.IntBuffermemSlice(java.nio.IntBuffer buffer, int offset, int capacity)Returns a slice of the specified buffer between(buffer.position() + offset)and(buffer.position() + offset + capacity).static java.nio.LongBuffermemSlice(java.nio.LongBuffer buffer)Slices the specified buffer.static java.nio.LongBuffermemSlice(java.nio.LongBuffer buffer, int offset, int capacity)Returns a slice of the specified buffer between(buffer.position() + offset)and(buffer.position() + offset + capacity).static java.nio.ShortBuffermemSlice(java.nio.ShortBuffer buffer)Slices the specified buffer.static java.nio.ShortBuffermemSlice(java.nio.ShortBuffer buffer, int offset, int capacity)Returns a slice of the specified buffer between(buffer.position() + offset)and(buffer.position() + offset + capacity).static <T extends CustomBuffer<T>>
TmemSlice(T buffer, int offset, int capacity)Returns a slice of the specified buffer between(buffer.position() + offset)and(buffer.position() + offset + capacity).static java.lang.StringmemUTF16(long address)Converts the null-terminated UTF-16 encoded string at the specified memory address to aString.static java.lang.StringmemUTF16(long address, int length)Converts the UTF-16 encoded string at the specified memory address to aString.static java.nio.ByteBuffermemUTF16(java.lang.CharSequence text)Returns a ByteBuffer containing the specified text UTF-16 encoded and null-terminated.static java.nio.ByteBuffermemUTF16(java.lang.CharSequence text, boolean nullTerminated)Returns a ByteBuffer containing the specified text UTF-16 encoded and optionally null-terminated.static intmemUTF16(java.lang.CharSequence text, boolean nullTerminated, java.nio.ByteBuffer target)Encodes and optionally null-terminates the specified text using UTF-16 encoding.static intmemUTF16(java.lang.CharSequence text, boolean nullTerminated, java.nio.ByteBuffer target, int offset)Encodes and optionally null-terminates the specified text using UTF-16 encoding.static java.lang.StringmemUTF16(java.nio.ByteBuffer buffer)Decodes the bytes with index[position(), position()+remaining()) inbuffer, as a UTF-16 string.static java.lang.StringmemUTF16(java.nio.ByteBuffer buffer, int length)Decodes the bytes with index[position(), position()+(length*2)) inbuffer, as a UTF-16 string.static java.lang.StringmemUTF16(java.nio.ByteBuffer buffer, int length, int offset)Decodes the bytes with index[offset, offset+(length*2)) inbuffer, as a UTF-16 string.static java.lang.StringmemUTF16Safe(long address)static java.lang.StringmemUTF16Safe(long address, int length)static java.nio.ByteBuffermemUTF16Safe(java.lang.CharSequence text)static java.nio.ByteBuffermemUTF16Safe(java.lang.CharSequence text, boolean nullTerminated)static java.lang.StringmemUTF16Safe(java.nio.ByteBuffer buffer)static java.lang.StringmemUTF8(long address)Converts the null-terminated UTF-8 encoded string at the specified memory address to aString.static java.lang.StringmemUTF8(long address, int length)Converts the UTF-8 encoded string at the specified memory address to aString.static java.nio.ByteBuffermemUTF8(java.lang.CharSequence text)Returns a ByteBuffer containing the specified text UTF-8 encoded and null-terminated.static java.nio.ByteBuffermemUTF8(java.lang.CharSequence text, boolean nullTerminated)Returns a ByteBuffer containing the specified text UTF-8 encoded and optionally null-terminated.static intmemUTF8(java.lang.CharSequence text, boolean nullTerminated, java.nio.ByteBuffer target)Encodes and optionally null-terminates the specified text using UTF-8 encoding.static intmemUTF8(java.lang.CharSequence text, boolean nullTerminated, java.nio.ByteBuffer target, int offset)Encodes and optionally null-terminates the specified text using UTF-8 encoding.static java.lang.StringmemUTF8(java.nio.ByteBuffer buffer)Decodes the bytes with index[position(), position()+remaining()) inbuffer, as a UTF-8 string.static java.lang.StringmemUTF8(java.nio.ByteBuffer buffer, int length)Decodes the bytes with index[position(), position()+length) inbuffer, as a UTF-8 string.static java.lang.StringmemUTF8(java.nio.ByteBuffer buffer, int length, int offset)Decodes the bytes with index[offset, offset+length) inbuffer, as a UTF-8 string.static java.lang.StringmemUTF8Safe(long address)static java.lang.StringmemUTF8Safe(long address, int length)static java.nio.ByteBuffermemUTF8Safe(java.lang.CharSequence text)static java.nio.ByteBuffermemUTF8Safe(java.lang.CharSequence text, boolean nullTerminated)static java.lang.StringmemUTF8Safe(java.nio.ByteBuffer buffer)static longnmemAlignedAlloc(long alignment, long size)Unsafe version ofmemAlignedAlloc(int, int).static longnmemAlignedAllocChecked(long alignment, long size)Unsafe version ofmemAlignedAlloc(int, int)that checks the returned pointer.static voidnmemAlignedFree(long ptr)Unsafe version ofmemAlignedFree(java.nio.ByteBuffer).static longnmemAlloc(long size)Unsafe version ofmemAlloc(int).static longnmemAllocChecked(long size)Unsafe version ofmemAlloc(int)that checks the returned pointer.static longnmemCalloc(long num, long size)Unsafe version ofmemCalloc(int, int).static longnmemCallocChecked(long num, long size)Unsafe version ofmemCalloc(int, int)that checks the returned pointer.static voidnmemFree(long ptr)Unsafe version ofmemFree(java.nio.Buffer).static longnmemRealloc(long ptr, long size)Unsafe version ofmemRealloc(java.nio.ByteBuffer, int).static longnmemReallocChecked(long ptr, long size)Unsafe version ofmemRealloc(java.nio.ByteBuffer, int)that checks the returned pointer.
-
-
-
Field Detail
-
NULL
Alias for the null pointer address.
-
PAGE_SIZE
The memory page size, in bytes. This value is always a power-of-two.
-
CACHE_LINE_SIZE
The cache-line size, in bytes. This value is always a power-of-two.
-
-
Method Detail
-
getAllocator
public static MemoryUtil.MemoryAllocator getAllocator()
Returns theMemoryUtil.MemoryAllocatorinstance used internally by the explicit memory management API (memAlloc(int),memFree(java.nio.Buffer), etc).Allocations made through the returned instance will not be tracked for memory leaks, even if
Configuration.DEBUG_MEMORY_ALLOCATORis enabled. This can be useful forstatic finalallocations that live throughout the application's lifetime and will never be freed until the process is terminated. Normally such allocations would be reported as memory leaks by the debug allocator.The expectation is that this method will rarely be used, so it does not have the
memprefix to avoid pollution of auto-complete lists.- Returns:
- the
MemoryUtil.MemoryAllocatorinstance
-
getAllocator
public static MemoryUtil.MemoryAllocator getAllocator(boolean tracked)
Returns theMemoryUtil.MemoryAllocatorinstance used internally by the explicit memory management API (memAlloc(int),memFree(java.nio.Buffer), etc).- Parameters:
tracked- whether allocations will be tracked for memory leaks, ifConfiguration.DEBUG_MEMORY_ALLOCATORis enabled.- Returns:
- the
MemoryUtil.MemoryAllocatorinstance
-
nmemAlloc
public static long nmemAlloc(long size)
-
nmemAllocChecked
public static long nmemAllocChecked(long size)
Unsafe version ofmemAlloc(int)that checks the returned pointer.- Returns:
- a pointer to the memory block allocated by the function on success. This pointer will never be
NULL, even ifsizeis zero. - Throws:
java.lang.OutOfMemoryError- if the function failed to allocate the requested block of memory
-
memAlloc
public static java.nio.ByteBuffer memAlloc(int size)
The standard C malloc function.Allocates a block of
sizebytes of memory, returning a pointer to the beginning of the block. The content of the newly allocated block of memory is not initialized, remaining with indeterminate values.Memory allocated with this method must be freed with
memFree(java.nio.Buffer).- Parameters:
size- the size of the memory block to allocate, in bytes. Ifsizeis zero, the returned pointer shall not be dereferenced.- Returns:
- on success, a pointer to the memory block allocated by the function
- Throws:
java.lang.OutOfMemoryError- if the function failed to allocate the requested block of memory
-
memAllocShort
public static java.nio.ShortBuffer memAllocShort(int size)
ShortBuffer version ofmemAlloc(int).- Parameters:
size- the number of short values to allocate.
-
memAllocInt
public static java.nio.IntBuffer memAllocInt(int size)
IntBuffer version ofmemAlloc(int).- Parameters:
size- the number of int values to allocate.
-
memAllocFloat
public static java.nio.FloatBuffer memAllocFloat(int size)
FloatBuffer version ofmemAlloc(int).- Parameters:
size- the number of float values to allocate.
-
memAllocLong
public static java.nio.LongBuffer memAllocLong(int size)
LongBuffer version ofmemAlloc(int).- Parameters:
size- the number of long values to allocate.
-
memAllocCLong
public static CLongBuffer memAllocCLong(int size)
CLongBufferversion ofmemAlloc(int).- Parameters:
size- the number of C long values to allocate.
-
memAllocDouble
public static java.nio.DoubleBuffer memAllocDouble(int size)
DoubleBuffer version ofmemAlloc(int).- Parameters:
size- the number of double values to allocate.
-
memAllocPointer
public static PointerBuffer memAllocPointer(int size)
PointerBuffer version ofmemAlloc(int).- Parameters:
size- the number of pointer values to allocate.
-
nmemFree
public static void nmemFree(long ptr)
Unsafe version ofmemFree(java.nio.Buffer).
-
memFree
public static void memFree(@Nullable java.nio.Buffer ptr)The standard C free function.A block of memory previously allocated by a call to
memAlloc(int),memCalloc(int, int)ormemRealloc(java.nio.ByteBuffer, int)is deallocated, making it available again for further allocations.- Parameters:
ptr- pointer to a memory block previously allocated withmemAlloc(int),memCalloc(int, int)ormemRealloc(java.nio.ByteBuffer, int). Ifptrdoes not point to a block of memory allocated with the above functions, it causes undefined behavior. Ifptris aNULLpointer, the function does nothing.
-
memFree
public static void memFree(@Nullable CustomBuffer ptr)CustomBufferversion ofmemFree(java.nio.Buffer).
-
nmemCalloc
public static long nmemCalloc(long num, long size)Unsafe version ofmemCalloc(int, int). May returnNULLifnumorsizeare zero or the allocation failed.
-
nmemCallocChecked
public static long nmemCallocChecked(long num, long size)Unsafe version ofmemCalloc(int, int)that checks the returned pointer.- Returns:
- a pointer to the memory block allocated by the function on success. This pointer will never be
NULL, even ifnumorsizeare zero. - Throws:
java.lang.OutOfMemoryError- if the function failed to allocate the requested block of memory
-
memCalloc
public static java.nio.ByteBuffer memCalloc(int num, int size)The standard C calloc function.Allocates a block of memory for an array of
numelements, each of themsizebytes long, and initializes all its bits to zero. The effective result is the allocation of a zero-initialized memory block of(num*size)bytes.Memory allocated with this method must be freed with
memFree(java.nio.Buffer).- Parameters:
num- the number of elements to allocate.size- the size of each element. Ifsizeis zero, the return value depends on the particular library implementation (it may or may not be a null pointer), but the returned pointer shall not be dereferenced.- Returns:
- on success, a pointer to the memory block allocated by the function
- Throws:
java.lang.OutOfMemoryError- if the function failed to allocate the requested block of memory
-
memCalloc
public static java.nio.ByteBuffer memCalloc(int num)
Alternative version ofmemCalloc(int, int).- Parameters:
num- the number of bytes to allocate.
-
memCallocShort
public static java.nio.ShortBuffer memCallocShort(int num)
ShortBuffer version ofmemCalloc(int, int).- Parameters:
num- the number of short values to allocate.
-
memCallocInt
public static java.nio.IntBuffer memCallocInt(int num)
IntBuffer version ofmemCalloc(int, int).- Parameters:
num- the number of int values to allocate.
-
memCallocFloat
public static java.nio.FloatBuffer memCallocFloat(int num)
FloatBuffer version ofmemCalloc(int, int).- Parameters:
num- the number of float values to allocate.
-
memCallocLong
public static java.nio.LongBuffer memCallocLong(int num)
LongBuffer version ofmemCalloc(int, int).- Parameters:
num- the number of long values to allocate.
-
memCallocCLong
public static CLongBuffer memCallocCLong(int num)
CLongBufferversion ofmemCalloc(int, int).- Parameters:
num- the number of C long values to allocate.
-
memCallocDouble
public static java.nio.DoubleBuffer memCallocDouble(int num)
DoubleBuffer version ofmemCalloc(int, int).- Parameters:
num- the number of double values to allocate.
-
memCallocPointer
public static PointerBuffer memCallocPointer(int num)
PointerBuffer version ofmemCalloc(int, int).- Parameters:
num- the number of pointer values to allocate.
-
nmemRealloc
public static long nmemRealloc(long ptr, long size)Unsafe version ofmemRealloc(java.nio.ByteBuffer, int). May returnNULLifsizeis zero or the allocation failed.
-
nmemReallocChecked
public static long nmemReallocChecked(long ptr, long size)Unsafe version ofmemRealloc(java.nio.ByteBuffer, int)that checks the returned pointer.- Returns:
- a pointer to the memory block reallocated by the function on success. This pointer will never be
NULL, even ifsizeis zero. - Throws:
java.lang.OutOfMemoryError- if the function failed to allocate the requested block of memory
-
memRealloc
public static java.nio.ByteBuffer memRealloc(@Nullable java.nio.ByteBuffer ptr, int size)The standard C realloc function.Changes the size of the memory block pointed to by
ptr. The function may move the memory block to a new location (whose address is returned by the function). The content of the memory block is preserved up to the lesser of the new and old sizes, even if the block is moved to a new location. If the new size is larger, the value of the newly allocated portion is indeterminate.The memory address used is always the address at the start of
ptr, so the current position ofptrdoes not need to be set to 0 for this function to work. The current position is preserved, even if the memory block is moved to a new location, unlesssizeis less than the current position in which case position will be equal to capacity. The limit is set to the capacity, and the mark is discarded.- Parameters:
ptr- a pointer to a memory block previously allocated withmemAlloc(int),memCalloc(int, int)ormemRealloc(java.nio.ByteBuffer, int). Alternatively, this can be aNULLpointer, in which case a new block is allocated (as ifmemAlloc(int)was called).size- the new size for the memory block, in bytes.- Returns:
- a pointer to the reallocated memory block, which may be either the same as
ptror a new location - Throws:
java.lang.OutOfMemoryError- if the function failed to allocate the requested block of memory. The memory block pointed to by argumentptris not deallocated (it is still valid, and with its contents unchanged).
-
memRealloc
public static java.nio.ShortBuffer memRealloc(@Nullable java.nio.ShortBuffer ptr, int size)ShortBuffer version ofmemRealloc(java.nio.ByteBuffer, int).- Parameters:
size- the number of short values to allocate.
-
memRealloc
public static java.nio.IntBuffer memRealloc(@Nullable java.nio.IntBuffer ptr, int size)IntBuffer version ofmemRealloc(java.nio.ByteBuffer, int).- Parameters:
size- the number of int values to allocate.
-
memRealloc
public static java.nio.LongBuffer memRealloc(@Nullable java.nio.LongBuffer ptr, int size)LongBuffer version ofmemRealloc(java.nio.ByteBuffer, int).- Parameters:
size- the number of long values to allocate.
-
memRealloc
public static CLongBuffer memRealloc(@Nullable CLongBuffer ptr, int size)
CLongBufferversion ofmemRealloc(java.nio.ByteBuffer, int).- Parameters:
size- the number of C long values to allocate.
-
memRealloc
public static java.nio.FloatBuffer memRealloc(@Nullable java.nio.FloatBuffer ptr, int size)FloatBuffer version ofmemRealloc(java.nio.ByteBuffer, int).- Parameters:
size- the number of float values to allocate.
-
memRealloc
public static java.nio.DoubleBuffer memRealloc(@Nullable java.nio.DoubleBuffer ptr, int size)DoubleBuffer version ofmemRealloc(java.nio.ByteBuffer, int).- Parameters:
size- the number of double values to allocate.
-
memRealloc
public static PointerBuffer memRealloc(@Nullable PointerBuffer ptr, int size)
PointerBuffer version ofmemRealloc(java.nio.ByteBuffer, int).- Parameters:
size- the number of pointer values to allocate.
-
nmemAlignedAlloc
public static long nmemAlignedAlloc(long alignment, long size)Unsafe version ofmemAlignedAlloc(int, int). May returnNULLifsizeis zero or the allocation failed.
-
nmemAlignedAllocChecked
public static long nmemAlignedAllocChecked(long alignment, long size)Unsafe version ofmemAlignedAlloc(int, int)that checks the returned pointer.- Returns:
- a pointer to the memory block allocated by the function on success. This pointer will never be
NULL, even ifsizeis zero. - Throws:
java.lang.OutOfMemoryError- if the function failed to allocate the requested block of memory
-
memAlignedAlloc
public static java.nio.ByteBuffer memAlignedAlloc(int alignment, int size)The standard C aligned_alloc function.Allocate
sizebytes of uninitialized storage whose alignment is specified byalignment. The size parameter must be an integral multiple of alignment. Memory allocated with memAlignedAlloc() must be freed withmemAlignedFree(java.nio.ByteBuffer).- Parameters:
alignment- the alignment. Must be a power of two value and a multiple ofsizeof(void *).size- the number of bytes to allocate. Must be a multiple ofalignment.
-
nmemAlignedFree
public static void nmemAlignedFree(long ptr)
Unsafe version ofmemAlignedFree(java.nio.ByteBuffer).
-
memAlignedFree
public static void memAlignedFree(@Nullable java.nio.ByteBuffer ptr)Frees a block of memory that was allocated withmemAlignedAlloc(int, int). If ptr isNULL, no operation is performed.- Parameters:
ptr- the aligned block of memory to free
-
memReport
public static void memReport(MemoryUtil.MemoryAllocationReport report)
Reports all live allocations.This method can only be used if the
Configuration.DEBUG_MEMORY_ALLOCATORoption has been set to true.- Parameters:
report- the report callback
-
memReport
public static void memReport(MemoryUtil.MemoryAllocationReport report, MemoryUtil.MemoryAllocationReport.Aggregate groupByStackTrace, boolean groupByThread)
Reports aggregates for the live allocations.This method can only be used if the
Configuration.DEBUG_MEMORY_ALLOCATORoption has been set to true.- Parameters:
report- the report callbackgroupByStackTrace- how to aggregate the reported allocationsgroupByThread- if the reported allocations should be grouped by thread
-
memAddress0
public static long memAddress0(java.nio.Buffer buffer)
Returns the memory address of the specified buffer. [INTERNAL USE ONLY]- Parameters:
buffer- the buffer- Returns:
- the memory address
-
memAddress
public static long memAddress(java.nio.ByteBuffer buffer)
Returns the memory address at the current position of the specified buffer. This is effectively a pointer value that can be used in native function calls.- Parameters:
buffer- the buffer- Returns:
- the memory address
-
memAddress
public static long memAddress(java.nio.ByteBuffer buffer, int position)Returns the memory address at the specified position of the specified buffer.- Parameters:
buffer- the bufferposition- the buffer position- Returns:
- the memory address
- See Also:
memAddress(ByteBuffer)
-
memAddress
public static long memAddress(java.nio.ShortBuffer buffer)
ShortBuffer version ofmemAddress(ByteBuffer).
-
memAddress
public static long memAddress(java.nio.ShortBuffer buffer, int position)ShortBuffer version ofmemAddress(ByteBuffer, int).
-
memAddress
public static long memAddress(java.nio.CharBuffer buffer)
CharBuffer version ofmemAddress(ByteBuffer).
-
memAddress
public static long memAddress(java.nio.CharBuffer buffer, int position)CharBuffer version ofmemAddress(ByteBuffer, int).
-
memAddress
public static long memAddress(java.nio.IntBuffer buffer)
IntBuffer version ofmemAddress(ByteBuffer).
-
memAddress
public static long memAddress(java.nio.IntBuffer buffer, int position)IntBuffer version ofmemAddress(ByteBuffer, int).
-
memAddress
public static long memAddress(java.nio.FloatBuffer buffer)
FloatBuffer version ofmemAddress(ByteBuffer).
-
memAddress
public static long memAddress(java.nio.FloatBuffer buffer, int position)FloatBuffer version ofmemAddress(ByteBuffer, int).
-
memAddress
public static long memAddress(java.nio.LongBuffer buffer)
LongBuffer version ofmemAddress(ByteBuffer).
-
memAddress
public static long memAddress(java.nio.LongBuffer buffer, int position)LongBuffer version ofmemAddress(ByteBuffer, int).
-
memAddress
public static long memAddress(java.nio.DoubleBuffer buffer)
DoubleBuffer version ofmemAddress(ByteBuffer).
-
memAddress
public static long memAddress(java.nio.DoubleBuffer buffer, int position)DoubleBuffer version ofmemAddress(ByteBuffer, int).
-
memAddress
public static long memAddress(java.nio.Buffer buffer)
Polymorphic version ofmemAddress(ByteBuffer).
-
memAddress
public static long memAddress(CustomBuffer<?> buffer)
CustomBuffer version ofmemAddress(ByteBuffer).
-
memAddress
public static long memAddress(CustomBuffer<?> buffer, int position)
CustomBuffer version ofmemAddress(ByteBuffer, int).
-
memAddressSafe
public static long memAddressSafe(@Nullable java.nio.ByteBuffer buffer)Null-safe version ofmemAddress(ByteBuffer). ReturnsNULLif the specified buffer is null.
-
memAddressSafe
public static long memAddressSafe(@Nullable java.nio.ShortBuffer buffer)ShortBuffer version ofmemAddressSafe(ByteBuffer).
-
memAddressSafe
public static long memAddressSafe(@Nullable java.nio.CharBuffer buffer)CharBuffer version ofmemAddressSafe(ByteBuffer).
-
memAddressSafe
public static long memAddressSafe(@Nullable java.nio.IntBuffer buffer)IntBuffer version ofmemAddressSafe(ByteBuffer).
-
memAddressSafe
public static long memAddressSafe(@Nullable java.nio.FloatBuffer buffer)FloatBuffer version ofmemAddressSafe(ByteBuffer).
-
memAddressSafe
public static long memAddressSafe(@Nullable java.nio.LongBuffer buffer)LongBuffer version ofmemAddressSafe(ByteBuffer).
-
memAddressSafe
public static long memAddressSafe(@Nullable java.nio.DoubleBuffer buffer)DoubleBuffer version ofmemAddressSafe(ByteBuffer).
-
memAddressSafe
public static long memAddressSafe(@Nullable Pointer pointer)Pointer version ofmemAddressSafe(ByteBuffer).
-
memByteBuffer
public static java.nio.ByteBuffer memByteBuffer(long address, int capacity)Creates a new direct ByteBuffer that starts at the specified memory address and has the specified capacity. The returned ByteBuffer instance will be set to the nativeByteOrder.- Parameters:
address- the starting memory addresscapacity- the buffer capacity- Returns:
- the new ByteBuffer
-
memByteBufferSafe
@Nullable public static java.nio.ByteBuffer memByteBufferSafe(long address, int capacity)
-
memByteBuffer
public static java.nio.ByteBuffer memByteBuffer(java.nio.ShortBuffer buffer)
Creates aByteBufferinstance as a view of the specifiedShortBufferbetween its current position and limit.This operation is the inverse of
ByteBuffer.asShortBuffer(). The returnedByteBufferinstance will be set to the nativeByteOrder.- Parameters:
buffer- the source buffer- Returns:
- the
ByteBufferview
-
memByteBuffer
public static java.nio.ByteBuffer memByteBuffer(java.nio.CharBuffer buffer)
Creates aByteBufferinstance as a view of the specifiedCharBufferbetween its current position and limit.This operation is the inverse of
ByteBuffer.asCharBuffer(). The returnedByteBufferinstance will be set to the nativeByteOrder.- Parameters:
buffer- the source buffer- Returns:
- the
ByteBufferview
-
memByteBuffer
public static java.nio.ByteBuffer memByteBuffer(java.nio.IntBuffer buffer)
Creates aByteBufferinstance as a view of the specifiedIntBufferbetween its current position and limit.This operation is the inverse of
ByteBuffer.asIntBuffer(). The returnedByteBufferinstance will be set to the nativeByteOrder.- Parameters:
buffer- the source buffer- Returns:
- the
ByteBufferview
-
memByteBuffer
public static java.nio.ByteBuffer memByteBuffer(java.nio.LongBuffer buffer)
Creates aByteBufferinstance as a view of the specifiedLongBufferbetween its current position and limit.This operation is the inverse of
ByteBuffer.asLongBuffer(). The returnedByteBufferinstance will be set to the nativeByteOrder.- Parameters:
buffer- the source buffer- Returns:
- the
ByteBufferview
-
memByteBuffer
public static java.nio.ByteBuffer memByteBuffer(java.nio.FloatBuffer buffer)
Creates aByteBufferinstance as a view of the specifiedFloatBufferbetween its current position and limit.This operation is the inverse of
ByteBuffer.asFloatBuffer(). The returnedByteBufferinstance will be set to the nativeByteOrder.- Parameters:
buffer- the source buffer- Returns:
- the
ByteBufferview
-
memByteBuffer
public static java.nio.ByteBuffer memByteBuffer(java.nio.DoubleBuffer buffer)
Creates aByteBufferinstance as a view of the specifiedDoubleBufferbetween its current position and limit.This operation is the inverse of
ByteBuffer.asDoubleBuffer(). The returnedByteBufferinstance will be set to the nativeByteOrder.- Parameters:
buffer- the source buffer- Returns:
- the
ByteBufferview
-
memByteBuffer
public static java.nio.ByteBuffer memByteBuffer(CustomBuffer<?> buffer)
Creates aByteBufferinstance as a view of the specifiedCustomBufferbetween its current position and limit.The returned
ByteBufferinstance will be set to the nativeByteOrder.- Parameters:
buffer- the source buffer- Returns:
- the
ByteBufferview
-
memShortBuffer
public static java.nio.ShortBuffer memShortBuffer(long address, int capacity)Creates a new direct ShortBuffer that starts at the specified memory address and has the specified capacity.The
addressspecified must be aligned to 2 bytes. If not, usememByteBuffer(address, capacity * 2).asShortBuffer().- Parameters:
address- the starting memory addresscapacity- the buffer capacity- Returns:
- the new ShortBuffer
-
memShortBufferSafe
@Nullable public static java.nio.ShortBuffer memShortBufferSafe(long address, int capacity)
-
memCharBuffer
public static java.nio.CharBuffer memCharBuffer(long address, int capacity)Creates a new direct CharBuffer that starts at the specified memory address and has the specified capacity.The
addressspecified must be aligned to 2 bytes. If not, usememByteBuffer(address, capacity * 2).asCharBuffer().- Parameters:
address- the starting memory addresscapacity- the buffer capacity- Returns:
- the new CharBuffer
-
memCharBufferSafe
@Nullable public static java.nio.CharBuffer memCharBufferSafe(long address, int capacity)
-
memIntBuffer
public static java.nio.IntBuffer memIntBuffer(long address, int capacity)Creates a new direct IntBuffer that starts at the specified memory address and has the specified capacity.The
addressspecified must be aligned to 4 bytes. If not, usememByteBuffer(address, capacity * 4).asIntBuffer().- Parameters:
address- the starting memory addresscapacity- the buffer capacity- Returns:
- the new IntBuffer
-
memIntBufferSafe
@Nullable public static java.nio.IntBuffer memIntBufferSafe(long address, int capacity)
-
memLongBuffer
public static java.nio.LongBuffer memLongBuffer(long address, int capacity)Creates a new direct LongBuffer that starts at the specified memory address and has the specified capacity.The
addressspecified must be aligned to 8 bytes. If not, usememByteBuffer(address, capacity * 8).asLongBuffer().- Parameters:
address- the starting memory addresscapacity- the buffer capacity- Returns:
- the new LongBuffer
-
memLongBufferSafe
@Nullable public static java.nio.LongBuffer memLongBufferSafe(long address, int capacity)
-
memCLongBuffer
public static CLongBuffer memCLongBuffer(long address, int capacity)
Creates a new directCLongBufferthat starts at the specified memory address and has the specified capacity.The
addressspecified must be aligned to 8 bytes. If not, usememByteBuffer(address, capacity * 8).asLongBuffer().- Parameters:
address- the starting memory addresscapacity- the buffer capacity- Returns:
- the new
CLongBuffer
-
memCLongBufferSafe
@Nullable public static CLongBuffer memCLongBufferSafe(long address, int capacity)
-
memFloatBuffer
public static java.nio.FloatBuffer memFloatBuffer(long address, int capacity)Creates a new direct FloatBuffer that starts at the specified memory address and has the specified capacity.The
addressspecified must be aligned to 4 bytes. If not, usememByteBuffer(address, capacity * 4).asFloatBuffer().- Parameters:
address- the starting memory addresscapacity- the buffer capacity- Returns:
- the new FloatBuffer
-
memFloatBufferSafe
@Nullable public static java.nio.FloatBuffer memFloatBufferSafe(long address, int capacity)
-
memDoubleBuffer
public static java.nio.DoubleBuffer memDoubleBuffer(long address, int capacity)Creates a new direct DoubleBuffer that starts at the specified memory address and has the specified capacity.The
addressspecified must be aligned to 8 bytes. If not, usememByteBuffer(address, capacity * 8).asDoubleBuffer().- Parameters:
address- the starting memory addresscapacity- the buffer capacity- Returns:
- the new DoubleBuffer
-
memDoubleBufferSafe
@Nullable public static java.nio.DoubleBuffer memDoubleBufferSafe(long address, int capacity)
-
memPointerBuffer
public static PointerBuffer memPointerBuffer(long address, int capacity)
Creates a new PointerBuffer that starts at the specified memory address and has the specified capacity.The
addressspecified must be aligned to the pointer size. If not, usePointerBuffer.create(memByteBuffer(address, capacity * POINTER_SIZE)).- Parameters:
address- the starting memory addresscapacity- the buffer capacity- Returns:
- the new PointerBuffer
-
memPointerBufferSafe
@Nullable public static PointerBuffer memPointerBufferSafe(long address, int capacity)
-
memDuplicate
public static java.nio.ByteBuffer memDuplicate(java.nio.ByteBuffer buffer)
Duplicates the specified buffer. The returned buffer will have the sameByteOrderas the source buffer.This method should be preferred over
ByteBuffer.duplicate()because it has a much shorter call chain. Long call chains may fail to inline due to JVM limits, disabling important optimizations (e.g. scalar replacement via Escape Analysis).- Parameters:
buffer- the buffer to duplicate- Returns:
- the duplicated buffer
-
memDuplicate
public static java.nio.ShortBuffer memDuplicate(java.nio.ShortBuffer buffer)
Duplicates the specified buffer.This method should be preferred over
ShortBuffer.duplicate()because it has a much shorter call chain. Long call chains may fail to inline due to JVM limits, disabling important optimizations (e.g. scalar replacement via Escape Analysis).- Parameters:
buffer- the buffer to duplicate- Returns:
- the duplicated buffer
-
memDuplicate
public static java.nio.CharBuffer memDuplicate(java.nio.CharBuffer buffer)
Duplicates the specified buffer.This method should be preferred over
CharBuffer.duplicate()because it has a much shorter call chain. Long call chains may fail to inline due to JVM limits, disabling important optimizations (e.g. scalar replacement via Escape Analysis).- Parameters:
buffer- the buffer to duplicate- Returns:
- the duplicated buffer
-
memDuplicate
public static java.nio.IntBuffer memDuplicate(java.nio.IntBuffer buffer)
Duplicates the specified buffer.This method should be preferred over
IntBuffer.duplicate()because it has a much shorter call chain. Long call chains may fail to inline due to JVM limits, disabling important optimizations (e.g. scalar replacement via Escape Analysis).- Parameters:
buffer- the buffer to duplicate- Returns:
- the duplicated buffer
-
memDuplicate
public static java.nio.LongBuffer memDuplicate(java.nio.LongBuffer buffer)
Duplicates the specified buffer.This method should be preferred over
LongBuffer.duplicate()because it has a much shorter call chain. Long call chains may fail to inline due to JVM limits, disabling important optimizations (e.g. scalar replacement via Escape Analysis).- Parameters:
buffer- the buffer to duplicate- Returns:
- the duplicated buffer
-
memDuplicate
public static java.nio.FloatBuffer memDuplicate(java.nio.FloatBuffer buffer)
Duplicates the specified buffer.This method should be preferred over
FloatBuffer.duplicate()because it has a much shorter call chain. Long call chains may fail to inline due to JVM limits, disabling important optimizations (e.g. scalar replacement via Escape Analysis).- Parameters:
buffer- the buffer to duplicate- Returns:
- the duplicated buffer
-
memDuplicate
public static java.nio.DoubleBuffer memDuplicate(java.nio.DoubleBuffer buffer)
Duplicates the specified buffer.This method should be preferred over
DoubleBuffer.duplicate()because it has a much shorter call chain. Long call chains may fail to inline due to JVM limits, disabling important optimizations (e.g. scalar replacement via Escape Analysis).- Parameters:
buffer- the buffer to duplicate- Returns:
- the duplicated buffer
-
memSlice
public static java.nio.ByteBuffer memSlice(java.nio.ByteBuffer buffer)
Slices the specified buffer. The returned buffer will have the sameByteOrderas the source buffer.This method should be preferred over
ByteBuffer.slice()because it has a much shorter call chain. Long call chains may fail to inline due to JVM limits, disabling important optimizations (e.g. scalar replacement via Escape Analysis).- Parameters:
buffer- the buffer to slice- Returns:
- the sliced buffer
-
memSlice
public static java.nio.ShortBuffer memSlice(java.nio.ShortBuffer buffer)
Slices the specified buffer.This method should be preferred over
ShortBuffer.slice()because it has a much shorter call chain. Long call chains may fail to inline due to JVM limits, disabling important optimizations (e.g. scalar replacement via Escape Analysis).- Parameters:
buffer- the buffer to slice- Returns:
- the sliced buffer
-
memSlice
public static java.nio.CharBuffer memSlice(java.nio.CharBuffer buffer)
Slices the specified buffer.This method should be preferred over
CharBuffer.slice()because it has a much shorter call chain. Long call chains may fail to inline due to JVM limits, disabling important optimizations (e.g. scalar replacement via Escape Analysis).- Parameters:
buffer- the buffer to slice- Returns:
- the sliced buffer
-
memSlice
public static java.nio.IntBuffer memSlice(java.nio.IntBuffer buffer)
Slices the specified buffer.This method should be preferred over
IntBuffer.slice()because it has a much shorter call chain. Long call chains may fail to inline due to JVM limits, disabling important optimizations (e.g. scalar replacement via Escape Analysis).- Parameters:
buffer- the buffer to slice- Returns:
- the sliced buffer
-
memSlice
public static java.nio.LongBuffer memSlice(java.nio.LongBuffer buffer)
Slices the specified buffer.This method should be preferred over
LongBuffer.slice()because it has a much shorter call chain. Long call chains may fail to inline due to JVM limits, disabling important optimizations (e.g. scalar replacement via Escape Analysis).- Parameters:
buffer- the buffer to slice- Returns:
- the sliced buffer
-
memSlice
public static java.nio.FloatBuffer memSlice(java.nio.FloatBuffer buffer)
Slices the specified buffer.This method should be preferred over
FloatBuffer.slice()because it has a much shorter call chain. Long call chains may fail to inline due to JVM limits, disabling important optimizations (e.g. scalar replacement via Escape Analysis).- Parameters:
buffer- the buffer to slice- Returns:
- the sliced buffer
-
memSlice
public static java.nio.DoubleBuffer memSlice(java.nio.DoubleBuffer buffer)
Slices the specified buffer.This method should be preferred over
DoubleBuffer.slice()because it has a much shorter call chain. Long call chains may fail to inline due to JVM limits, disabling important optimizations (e.g. scalar replacement via Escape Analysis).- Parameters:
buffer- the buffer to slice- Returns:
- the sliced buffer
-
memSlice
public static java.nio.ByteBuffer memSlice(java.nio.ByteBuffer buffer, int offset, int capacity)Returns a slice of the specified buffer between(buffer.position() + offset)and(buffer.position() + offset + capacity). The returned buffer will have the sameByteOrderas the original buffer.The position and limit of the original buffer are preserved after a call to this method.
- Parameters:
buffer- the buffer to sliceoffset- the slice offset, it must be ≤buffer.remaining()capacity- the slice length, it must be ≤buffer.capacity() - (buffer.position() + offset)- Returns:
- the sliced buffer
-
memSlice
public static java.nio.ShortBuffer memSlice(java.nio.ShortBuffer buffer, int offset, int capacity) public static java.nio.CharBuffer memSlice(java.nio.CharBuffer buffer, int offset, int capacity) public static java.nio.IntBuffer memSlice(java.nio.IntBuffer buffer, int offset, int capacity) public static java.nio.LongBuffer memSlice(java.nio.LongBuffer buffer, int offset, int capacity) public static java.nio.FloatBuffer memSlice(java.nio.FloatBuffer buffer, int offset, int capacity) public static java.nio.DoubleBuffer memSlice(java.nio.DoubleBuffer buffer, int offset, int capacity)Returns a slice of the specified buffer between(buffer.position() + offset)and(buffer.position() + offset + capacity).The position and limit of the original buffer are preserved after a call to this method.
- Parameters:
buffer- the buffer to sliceoffset- the slice offset, it must be ≤buffer.remaining()capacity- the slice length, it must be ≤buffer.capacity() - (buffer.position() + offset)- Returns:
- the sliced buffer
-
memSlice
public static <T extends CustomBuffer<T>> T memSlice(T buffer, int offset, int capacity)
Returns a slice of the specified buffer between(buffer.position() + offset)and(buffer.position() + offset + capacity).The position and limit of the original buffer are preserved after a call to this method.
- Parameters:
buffer- the buffer to sliceoffset- the slice offset, it must be ≤buffer.remaining()capacity- the slice length, it must be ≤buffer.capacity() - (buffer.position() + offset)- Returns:
- the sliced buffer
-
memSet
public static void memSet(java.nio.ByteBuffer ptr, int value) public static void memSet(java.nio.ShortBuffer ptr, int value) public static void memSet(java.nio.CharBuffer ptr, int value) public static void memSet(java.nio.IntBuffer ptr, int value) public static void memSet(java.nio.LongBuffer ptr, int value) public static void memSet(java.nio.FloatBuffer ptr, int value) public static void memSet(java.nio.DoubleBuffer ptr, int value)Sets all bytes in a specified block of memory to a fixed value (usually zero).- Parameters:
ptr- the starting memory addressvalue- the value to set (memSet will convert it to unsigned byte)
-
memSet
public static <T extends CustomBuffer<T>> void memSet(T ptr, int value)
Sets all bytes in a specified block of memory to a fixed value (usually zero).- Type Parameters:
T- the buffer type- Parameters:
ptr- the starting memory addressvalue- the value to set (memSet will convert it to unsigned byte)
-
memSet
public static <T extends Struct> void memSet(T ptr, int value)
Sets all bytes in a specified block of memory to a fixed value (usually zero).- Type Parameters:
T- the struct type- Parameters:
ptr- the starting memory addressvalue- the value to set (memSet will convert it to unsigned byte)
-
memCopy
public static void memCopy(java.nio.ByteBuffer src, java.nio.ByteBuffer dst) public static void memCopy(java.nio.ShortBuffer src, java.nio.ShortBuffer dst) public static void memCopy(java.nio.CharBuffer src, java.nio.CharBuffer dst) public static void memCopy(java.nio.IntBuffer src, java.nio.IntBuffer dst) public static void memCopy(java.nio.LongBuffer src, java.nio.LongBuffer dst) public static void memCopy(java.nio.FloatBuffer src, java.nio.FloatBuffer dst) public static void memCopy(java.nio.DoubleBuffer src, java.nio.DoubleBuffer dst)Sets all bytes in a specified block of memory to a copy of another block.- Parameters:
src- the source memory addressdst- the destination memory address
-
memCopy
public static <T extends CustomBuffer<T>> void memCopy(T src, T dst)
Sets all bytes in a specified block of memory to a copy of another block.- Type Parameters:
T- the buffer type- Parameters:
src- the source memory addressdst- the destination memory address
-
memCopy
public static <T extends Struct> void memCopy(T src, T dst)
Sets all bytes of a struct to a copy of another struct.- Type Parameters:
T- the struct type- Parameters:
src- the source structdst- the destination struct
-
memSet
public static void memSet(long ptr, int value, long bytes)Sets all bytes in a specified block of memory to a fixed value (usually zero).- Parameters:
ptr- the starting memory addressvalue- the value to set (memSet will convert it to unsigned byte)bytes- the number of bytes to set
-
memCopy
public static void memCopy(long src, long dst, long bytes)Sets all bytes in a specified block of memory to a copy of another block.- Parameters:
src- the source memory addressdst- the destination memory addressbytes- the number of bytes to copy
-
memGetBoolean
public static boolean memGetBoolean(long ptr)
-
memGetByte
public static byte memGetByte(long ptr)
-
memGetShort
public static short memGetShort(long ptr)
-
memGetInt
public static int memGetInt(long ptr)
-
memGetLong
public static long memGetLong(long ptr)
-
memGetFloat
public static float memGetFloat(long ptr)
-
memGetDouble
public static double memGetDouble(long ptr)
-
memGetCLong
public static long memGetCLong(long ptr)
-
memGetAddress
public static long memGetAddress(long ptr)
-
memPutByte
public static void memPutByte(long ptr, byte value)
-
memPutShort
public static void memPutShort(long ptr, short value)
-
memPutInt
public static void memPutInt(long ptr, int value)
-
memPutLong
public static void memPutLong(long ptr, long value)
-
memPutFloat
public static void memPutFloat(long ptr, float value)
-
memPutDouble
public static void memPutDouble(long ptr, double value)
-
memPutCLong
public static void memPutCLong(long ptr, long value)
-
memPutAddress
public static void memPutAddress(long ptr, long value)
-
memGlobalRefToObject
public static <T> T memGlobalRefToObject(long globalRef)
Returns the object that the specified global reference points to.- Type Parameters:
T- the object type- Parameters:
globalRef- the global reference- Returns:
- the object pointed to by
globalRef
-
memNewGlobalRef
@Deprecated public static long memNewGlobalRef(java.lang.Object obj)
Deprecated.Deprecated, useJNINativeInterface.NewGlobalRef(java.lang.Object)instead.
-
memDeleteGlobalRef
@Deprecated public static void memDeleteGlobalRef(long globalRef)
Deprecated.Deprecated, useJNINativeInterface.DeleteGlobalRef(long)instead.
-
memNewWeakGlobalRef
@Deprecated public static long memNewWeakGlobalRef(java.lang.Object obj)
Deprecated.Deprecated, useJNINativeInterface.NewWeakGlobalRef(java.lang.Object)instead.
-
memDeleteWeakGlobalRef
@Deprecated public static void memDeleteWeakGlobalRef(long globalRef)
Deprecated.Deprecated, useJNINativeInterface.DeleteWeakGlobalRef(long)instead.
-
memASCII
public static java.nio.ByteBuffer memASCII(java.lang.CharSequence text)
Returns a ByteBuffer containing the specified text ASCII encoded and null-terminated.- Parameters:
text- the text to encode- Returns:
- the encoded text. The returned buffer must be deallocated manually with
memFree(java.nio.Buffer).
-
memASCIISafe
@Nullable public static java.nio.ByteBuffer memASCIISafe(@Nullable java.lang.CharSequence text)
-
memASCII
public static java.nio.ByteBuffer memASCII(java.lang.CharSequence text, boolean nullTerminated)Returns a ByteBuffer containing the specified text ASCII encoded and optionally null-terminated.- Parameters:
text- the text to encodenullTerminated- if true, the text will be terminated with a '\0'.- Returns:
- the encoded text. The returned buffer must be deallocated manually with
memFree(java.nio.Buffer).
-
memASCIISafe
@Nullable public static java.nio.ByteBuffer memASCIISafe(@Nullable java.lang.CharSequence text, boolean nullTerminated)
-
memASCII
public static int memASCII(java.lang.CharSequence text, boolean nullTerminated, java.nio.ByteBuffer target)Encodes and optionally null-terminates the specified text using ASCII encoding. The encoded text is stored in the specifiedByteBuffer, at the current buffer position. The current buffer position is not modified by this operation. Thetargetbuffer is assumed to have enough remaining space to store the encoded text.- Parameters:
text- the text to encodenullTerminated- if true, the text will be terminated with a '\0'.- Returns:
- the number of bytes of the encoded string
-
memASCII
public static int memASCII(java.lang.CharSequence text, boolean nullTerminated, java.nio.ByteBuffer target, int offset)Encodes and optionally null-terminates the specified text using ASCII encoding. The encoded text is stored in the specifiedByteBufferat the specifiedpositionoffset. The current buffer position is not modified by this operation. Thetargetbuffer is assumed to have enough remaining space to store the encoded text.- Parameters:
text- the text to encodenullTerminated- if true, the text will be terminated with a '\0'.offset- the buffer position to which the string will be encoded- Returns:
- the number of bytes of the encoded string
-
memLengthASCII
public static int memLengthASCII(java.lang.CharSequence value, boolean nullTerminated)Returns the number of bytes required to encode the specified text in the ASCII encoding.- Parameters:
value- the text to encodenullTerminated- if true, add the number of bytes required for null-termination- Returns:
- the number of bytes
-
memUTF8
public static java.nio.ByteBuffer memUTF8(java.lang.CharSequence text)
Returns a ByteBuffer containing the specified text UTF-8 encoded and null-terminated.- Parameters:
text- the text to encode- Returns:
- the encoded text. The returned buffer must be deallocated manually with
memFree(java.nio.Buffer).
-
memUTF8Safe
@Nullable public static java.nio.ByteBuffer memUTF8Safe(@Nullable java.lang.CharSequence text)
-
memUTF8
public static java.nio.ByteBuffer memUTF8(java.lang.CharSequence text, boolean nullTerminated)Returns a ByteBuffer containing the specified text UTF-8 encoded and optionally null-terminated.- Parameters:
text- the text to encodenullTerminated- if true, the text will be terminated with a '\0'.- Returns:
- the encoded text. The returned buffer must be deallocated manually with
memFree(java.nio.Buffer).
-
memUTF8Safe
@Nullable public static java.nio.ByteBuffer memUTF8Safe(@Nullable java.lang.CharSequence text, boolean nullTerminated)
-
memUTF8
public static int memUTF8(java.lang.CharSequence text, boolean nullTerminated, java.nio.ByteBuffer target)Encodes and optionally null-terminates the specified text using UTF-8 encoding. The encoded text is stored in the specifiedByteBuffer, at the current buffer position. The current buffer position is not modified by this operation. Thetargetbuffer is assumed to have enough remaining space to store the encoded text. The specified text is assumed to be a valid UTF-16 string.- Parameters:
text- the text to encodenullTerminated- if true, the text will be terminated with a '\0'.target- the buffer in which to store the encoded text- Returns:
- the number of bytes of the encoded string
-
memUTF8
public static int memUTF8(java.lang.CharSequence text, boolean nullTerminated, java.nio.ByteBuffer target, int offset)Encodes and optionally null-terminates the specified text using UTF-8 encoding. The encoded text is stored in the specifiedByteBuffer, at the specifiedpositionoffset. The current buffer position is not modified by this operation. Thetargetbuffer is assumed to have enough remaining space to store the encoded text. The specified text is assumed to be a valid UTF-16 string.- Parameters:
text- the text to encodenullTerminated- if true, the text will be terminated with a '\0'.target- the buffer in which to store the encoded textoffset- the buffer position to which the string will be encoded- Returns:
- the number of bytes of the encoded string
-
memLengthUTF8
public static int memLengthUTF8(java.lang.CharSequence value, boolean nullTerminated)Returns the number of bytes required to encode the specified text in the UTF-8 encoding.- Parameters:
value- the text to encodenullTerminated- if true, add the number of bytes required for null-termination- Returns:
- the number of bytes
-
memUTF16
public static java.nio.ByteBuffer memUTF16(java.lang.CharSequence text)
Returns a ByteBuffer containing the specified text UTF-16 encoded and null-terminated.- Parameters:
text- the text to encode- Returns:
- the encoded text. The returned buffer must be deallocated manually with
memFree(java.nio.Buffer).
-
memUTF16Safe
@Nullable public static java.nio.ByteBuffer memUTF16Safe(@Nullable java.lang.CharSequence text)
-
memUTF16
public static java.nio.ByteBuffer memUTF16(java.lang.CharSequence text, boolean nullTerminated)Returns a ByteBuffer containing the specified text UTF-16 encoded and optionally null-terminated.- Parameters:
text- the text to encodenullTerminated- if true, the text will be terminated with a '\0'.- Returns:
- the encoded text. The returned buffer must be deallocated manually with
memFree(java.nio.Buffer).
-
memUTF16Safe
@Nullable public static java.nio.ByteBuffer memUTF16Safe(@Nullable java.lang.CharSequence text, boolean nullTerminated)
-
memUTF16
public static int memUTF16(java.lang.CharSequence text, boolean nullTerminated, java.nio.ByteBuffer target)Encodes and optionally null-terminates the specified text using UTF-16 encoding. The encoded text is stored in the specifiedByteBuffer, at the current buffer position. The current buffer position is not modified by this operation. Thetargetbuffer is assumed to have enough remaining space to store the encoded text.- Parameters:
text- the text to encodenullTerminated- if true, the text will be terminated with a '\0'.target- the buffer in which to store the encoded text- Returns:
- the number of bytes of the encoded string
-
memUTF16
public static int memUTF16(java.lang.CharSequence text, boolean nullTerminated, java.nio.ByteBuffer target, int offset)Encodes and optionally null-terminates the specified text using UTF-16 encoding. The encoded text is stored in the specifiedByteBufferat the specifiedpositionoffset. The current buffer position is not modified by this operation. Thetargetbuffer is assumed to have enough remaining space to store the encoded text.- Parameters:
text- the text to encodenullTerminated- if true, the text will be terminated with a '\0'.target- the buffer in which to store the encoded textoffset- the buffer position to which the string will be encoded- Returns:
- the number of bytes of the encoded string
-
memLengthUTF16
public static int memLengthUTF16(java.lang.CharSequence value, boolean nullTerminated)Returns the number of bytes required to encode the specified text in the UTF-16 encoding.- Parameters:
value- the text to encodenullTerminated- if true, add the number of bytes required for null-termination- Returns:
- the number of bytes
-
memLengthNT1
public static int memLengthNT1(java.nio.ByteBuffer buffer)
Calculates the length, in bytes, of the null-terminated string that starts at the current position of the specified buffer. A single \0 character will terminate the string. The returned length will NOT include the \0 byte.This method is useful for reading ASCII and UTF8 encoded text.
- Parameters:
buffer- the buffer containing the null-terminated string- Returns:
- the string length, in bytes
-
memLengthNT2
public static int memLengthNT2(java.nio.ByteBuffer buffer)
Calculates the length, in bytes, of the null-terminated string that starts at the current position of the specified buffer. Two \0 characters will terminate the string. The returned buffer will NOT include the \0 bytes.This method is useful for reading UTF16 encoded text.
- Parameters:
buffer- the buffer containing the null-terminated string- Returns:
- the string length, in bytes
-
memByteBufferNT1
public static java.nio.ByteBuffer memByteBufferNT1(long address)
Creates a new direct ByteBuffer that starts at the specified memory address and has capacity equal to the null-terminated string starting at that address. A single \0 character will terminate the string. The returned buffer will NOT include the \0 byte.This method is useful for reading ASCII and UTF8 encoded text.
- Parameters:
address- the starting memory address- Returns:
- the new ByteBuffer
-
memByteBufferNT1
public static java.nio.ByteBuffer memByteBufferNT1(long address, int maxLength)Creates a new direct ByteBuffer that starts at the specified memory address and has capacity equal to the null-terminated string starting at that address, up to a maximum ofmaxLengthbytes. A single \0 character will terminate the string. The returned buffer will NOT include the \0 byte.This method is useful for reading ASCII and UTF8 encoded text.
- Parameters:
address- the starting memory addressmaxLength- the maximum string length, in bytes- Returns:
- the new ByteBuffer
-
memByteBufferNT1Safe
@Nullable public static java.nio.ByteBuffer memByteBufferNT1Safe(long address)
-
memByteBufferNT1Safe
@Nullable public static java.nio.ByteBuffer memByteBufferNT1Safe(long address, int maxLength)
-
memByteBufferNT2
public static java.nio.ByteBuffer memByteBufferNT2(long address)
Creates a new direct ByteBuffer that starts at the specified memory address and has capacity equal to the null-terminated string starting at that address. Two \0 characters will terminate the string. The returned buffer will NOT include the \0 bytes.This method is useful for reading UTF16 encoded text.
- Parameters:
address- the starting memory address- Returns:
- the new ByteBuffer
-
memByteBufferNT2
public static java.nio.ByteBuffer memByteBufferNT2(long address, int maxLength)Creates a new direct ByteBuffer that starts at the specified memory address and has capacity equal to the null-terminated string starting at that address, up to a maximum ofmaxLengthbytes. Two \0 characters will terminate the string. The returned buffer will NOT include the \0 bytes.This method is useful for reading UTF16 encoded text.
- Parameters:
address- the starting memory address- Returns:
- the new ByteBuffer
-
memByteBufferNT2Safe
@Nullable public static java.nio.ByteBuffer memByteBufferNT2Safe(long address)
-
memByteBufferNT2Safe
@Nullable public static java.nio.ByteBuffer memByteBufferNT2Safe(long address, int maxLength)
-
memASCII
public static java.lang.String memASCII(long address)
Converts the null-terminated ASCII encoded string at the specified memory address to aString.- Parameters:
address- the string memory address- Returns:
- the decoded
String
-
memASCII
public static java.lang.String memASCII(long address, int length)Converts the ASCII encoded string at the specified memory address to aString.- Parameters:
address- the string memory addresslength- the number of bytes to decode- Returns:
- the decoded
String
-
memASCII
public static java.lang.String memASCII(java.nio.ByteBuffer buffer)
Decodes the bytes with index[position(), position()+remaining()) inbuffer, as an ASCII string.The current
positionandlimitof the specifiedbufferare not affected by this operation.- Parameters:
buffer- theByteBufferto decode- Returns:
- the decoded
String
-
memASCIISafe
@Nullable public static java.lang.String memASCIISafe(long address)
-
memASCIISafe
@Nullable public static java.lang.String memASCIISafe(long address, int length)
-
memASCIISafe
@Nullable public static java.lang.String memASCIISafe(@Nullable java.nio.ByteBuffer buffer)
-
memASCII
public static java.lang.String memASCII(java.nio.ByteBuffer buffer, int length)Decodes the bytes with index[position(), position()+length) inbuffer, as an ASCII string.The current
positionandlimitof the specifiedbufferare not affected by this operation.- Parameters:
buffer- theByteBufferto decodelength- the number of bytes to decode- Returns:
- the decoded
String
-
memASCII
public static java.lang.String memASCII(java.nio.ByteBuffer buffer, int length, int offset)Decodes the bytes with index[offset, offset+length) inbuffer, as an ASCII string.The current
positionandlimitof the specifiedbufferare not affected by this operation.- Parameters:
buffer- theByteBufferto decodelength- the number of bytes to decodeoffset- the offset at which to start decoding.- Returns:
- the decoded
String
-
memUTF8
public static java.lang.String memUTF8(long address)
Converts the null-terminated UTF-8 encoded string at the specified memory address to aString.- Parameters:
address- the string memory address- Returns:
- the decoded
String
-
memUTF8
public static java.lang.String memUTF8(long address, int length)Converts the UTF-8 encoded string at the specified memory address to aString.- Parameters:
address- the string memory addresslength- the number of bytes to decode- Returns:
- the decoded
String
-
memUTF8
public static java.lang.String memUTF8(java.nio.ByteBuffer buffer)
Decodes the bytes with index[position(), position()+remaining()) inbuffer, as a UTF-8 string.The current
positionandlimitof the specifiedbufferare not affected by this operation.- Parameters:
buffer- theByteBufferto decode- Returns:
- the decoded
String
-
memUTF8Safe
@Nullable public static java.lang.String memUTF8Safe(long address)
-
memUTF8Safe
@Nullable public static java.lang.String memUTF8Safe(long address, int length)
-
memUTF8Safe
@Nullable public static java.lang.String memUTF8Safe(@Nullable java.nio.ByteBuffer buffer)
-
memUTF8
public static java.lang.String memUTF8(java.nio.ByteBuffer buffer, int length)Decodes the bytes with index[position(), position()+length) inbuffer, as a UTF-8 string.The current
positionandlimitof the specifiedbufferare not affected by this operation.- Parameters:
buffer- theByteBufferto decodelength- the number of bytes to decode- Returns:
- the decoded
String
-
memUTF8
public static java.lang.String memUTF8(java.nio.ByteBuffer buffer, int length, int offset)Decodes the bytes with index[offset, offset+length) inbuffer, as a UTF-8 string.The current
positionandlimitof the specifiedbufferare not affected by this operation.- Parameters:
buffer- theByteBufferto decodelength- the number of bytes to decodeoffset- the offset at which to start decoding.- Returns:
- the decoded
String
-
memUTF16
public static java.lang.String memUTF16(long address)
Converts the null-terminated UTF-16 encoded string at the specified memory address to aString.- Parameters:
address- the string memory address- Returns:
- the decoded
String
-
memUTF16
public static java.lang.String memUTF16(long address, int length)Converts the UTF-16 encoded string at the specified memory address to aString.- Parameters:
address- the string memory addresslength- the number of characters to decode- Returns:
- the decoded
String
-
memUTF16
public static java.lang.String memUTF16(java.nio.ByteBuffer buffer)
Decodes the bytes with index[position(), position()+remaining()) inbuffer, as a UTF-16 string.The current
positionandlimitof the specifiedbufferare not affected by this operation.- Parameters:
buffer- theByteBufferto decode- Returns:
- the decoded
String
-
memUTF16Safe
@Nullable public static java.lang.String memUTF16Safe(long address)
-
memUTF16Safe
@Nullable public static java.lang.String memUTF16Safe(long address, int length)
-
memUTF16Safe
@Nullable public static java.lang.String memUTF16Safe(@Nullable java.nio.ByteBuffer buffer)
-
memUTF16
public static java.lang.String memUTF16(java.nio.ByteBuffer buffer, int length)Decodes the bytes with index[position(), position()+(length*2)) inbuffer, as a UTF-16 string.The current
positionandlimitof the specifiedbufferare not affected by this operation.- Parameters:
buffer- theByteBufferto decodelength- the number of characters to decode- Returns:
- the decoded
String
-
memUTF16
public static java.lang.String memUTF16(java.nio.ByteBuffer buffer, int length, int offset)Decodes the bytes with index[offset, offset+(length*2)) inbuffer, as a UTF-16 string.The current
positionandlimitof the specifiedbufferare not affected by this operation.- Parameters:
buffer- theByteBufferto decodelength- the number of characters to decodeoffset- the offset at which to start decoding, in bytes.- Returns:
- the decoded
String
-
-