Class MemoryUtil

java.lang.Object
org.lwjgl.system.MemoryUtil

public final class MemoryUtil extends Object
This class provides functionality for managing native memory.

Method names in this class are prefixed with mem to 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.)

The codec implementations may skip codepoint validation, for improved performance. Therefore, if malformed input or unmappable characters are expected, the JDK CharsetEncoder/CharsetDecoder classes should be used instead. Methods in bindings that accept/return CharSequence/String also support ByteBuffer, so custom codecs can be used if necessary.

This API is meant to be used with static import.

See Also:
  • Field Details

    • NULL

      public static final long NULL
      Alias for the null pointer address.
      See Also:
    • PAGE_SIZE

      public static final int PAGE_SIZE
      The memory page size, in bytes. This value is always a power-of-two.
    • CACHE_LINE_SIZE

      public static final int CACHE_LINE_SIZE
      The cache-line size, in bytes. This value is always a power-of-two.
  • Method Details

    • memBackend

      public static MemoryBackend memBackend()
      Returns the MemoryBackend instance used by LWJGL.
    • getAllocator

      public static MemoryUtil.MemoryAllocator getAllocator()
      Returns the MemoryUtil.MemoryAllocator instance used internally by the explicit memory management API (memAlloc(int), memFree(Buffer), etc).

      Allocations made through the returned instance will not be tracked for memory leaks, even if Configuration.DEBUG_MEMORY_ALLOCATOR is enabled. This can be useful for static final allocations 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 mem prefix to avoid pollution of auto-complete lists.

      Returns:
      the MemoryUtil.MemoryAllocator instance
    • getAllocator

      public static MemoryUtil.MemoryAllocator getAllocator(boolean tracked)
      Returns the MemoryUtil.MemoryAllocator instance used internally by the explicit memory management API (memAlloc(int), memFree(Buffer), etc).
      Parameters:
      tracked - whether allocations will be tracked for memory leaks, if Configuration.DEBUG_MEMORY_ALLOCATOR is enabled.
      Returns:
      the MemoryUtil.MemoryAllocator instance
    • nmemAlloc

      public static long nmemAlloc(long size)
      Unsafe version of memAlloc(int). May return NULL if size is zero or the allocation failed.
    • nmemAllocChecked

      public static long nmemAllocChecked(long size)
      Unsafe version of memAlloc(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 if size is zero.
      Throws:
      OutOfMemoryError - if the function failed to allocate the requested block of memory
    • memAlloc

      public static ByteBuffer memAlloc(int size)
      The standard C malloc function.

      Allocates a block of size bytes 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(Buffer).

      Parameters:
      size - the size of the memory block to allocate, in bytes. If size is zero, the returned pointer shall not be dereferenced.
      Returns:
      on success, a pointer to the memory block allocated by the function
      Throws:
      OutOfMemoryError - if the function failed to allocate the requested block of memory
    • memAllocChar

      public static CharBuffer memAllocChar(int size)
      CharBuffer version of memAlloc(int).
      Parameters:
      size - the number of char values to allocate.
    • memAllocShort

      public static ShortBuffer memAllocShort(int size)
      ShortBuffer version of memAlloc(int).
      Parameters:
      size - the number of short values to allocate.
    • memAllocInt

      public static IntBuffer memAllocInt(int size)
      IntBuffer version of memAlloc(int).
      Parameters:
      size - the number of int values to allocate.
    • memAllocFloat

      public static FloatBuffer memAllocFloat(int size)
      FloatBuffer version of memAlloc(int).
      Parameters:
      size - the number of float values to allocate.
    • memAllocLong

      public static LongBuffer memAllocLong(int size)
      LongBuffer version of memAlloc(int).
      Parameters:
      size - the number of long values to allocate.
    • memAllocCLong

      public static CLongBuffer memAllocCLong(int size)
      CLongBuffer version of memAlloc(int).
      Parameters:
      size - the number of C long values to allocate.
    • memAllocDouble

      public static DoubleBuffer memAllocDouble(int size)
      DoubleBuffer version of memAlloc(int).
      Parameters:
      size - the number of double values to allocate.
    • memAllocPointer

      public static PointerBuffer memAllocPointer(int size)
      PointerBuffer version of memAlloc(int).
      Parameters:
      size - the number of pointer values to allocate.
    • nmemFree

      public static void nmemFree(long ptr)
      Unsafe version of memFree(Buffer).
    • memFree

      public static void memFree(@Nullable Buffer ptr)
      The standard C free function.

      A block of memory previously allocated by a call to memAlloc(int), memCalloc(int, int) or memRealloc(ByteBuffer, int) is deallocated, making it available again for further allocations.

      Parameters:
      ptr - pointer to a memory block previously allocated with memAlloc(int), memCalloc(int, int) or memRealloc(ByteBuffer, int). If ptr does not point to a block of memory allocated with the above functions, it causes undefined behavior. If ptr is a NULL pointer, the function does nothing.
    • memFree

      public static void memFree(@Nullable ByteBuffer ptr)
      ByteBuffer version of memFree(Buffer).
    • memFree

      public static void memFree(@Nullable ShortBuffer ptr)
      ShortBuffer version of memFree(Buffer).
    • memFree

      public static void memFree(@Nullable CharBuffer ptr)
      CharBuffer version of memFree(Buffer).
    • memFree

      public static void memFree(@Nullable IntBuffer ptr)
      IntBuffer version of memFree(Buffer).
    • memFree

      public static void memFree(@Nullable LongBuffer ptr)
      LongBuffer version of memFree(Buffer).
    • memFree

      public static void memFree(@Nullable FloatBuffer ptr)
      FloatBuffer version of memFree(Buffer).
    • memFree

      public static void memFree(@Nullable DoubleBuffer ptr)
      DoubleBuffer version of memFree(Buffer).
    • memFree

      public static void memFree(@Nullable CustomBuffer<?> ptr)
      CustomBuffer version of memFree(Buffer).
    • nmemCalloc

      public static long nmemCalloc(long num, long size)
      Unsafe version of memCalloc(int, int). May return NULL if num or size are zero or the allocation failed.
    • nmemCallocChecked

      public static long nmemCallocChecked(long num, long size)
      Unsafe version of memCalloc(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 if num or size are zero.
      Throws:
      OutOfMemoryError - if the function failed to allocate the requested block of memory
    • memCalloc

      public static ByteBuffer memCalloc(int num, int size)
      The standard C calloc function.

      Allocates a block of memory for an array of num elements, each of them size bytes 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(Buffer).

      Parameters:
      num - the number of elements to allocate.
      size - the size of each element. If size is 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:
      OutOfMemoryError - if the function failed to allocate the requested block of memory
    • memCalloc

      public static ByteBuffer memCalloc(int num)
      Alternative version of memCalloc(int, int).
      Parameters:
      num - the number of bytes to allocate.
    • memCallocChar

      public static CharBuffer memCallocChar(int num)
      CharBuffer version of memCalloc(int, int).
      Parameters:
      num - the number of short values to allocate.
    • memCallocShort

      public static ShortBuffer memCallocShort(int num)
      ShortBuffer version of memCalloc(int, int).
      Parameters:
      num - the number of short values to allocate.
    • memCallocInt

      public static IntBuffer memCallocInt(int num)
      IntBuffer version of memCalloc(int, int).
      Parameters:
      num - the number of int values to allocate.
    • memCallocFloat

      public static FloatBuffer memCallocFloat(int num)
      FloatBuffer version of memCalloc(int, int).
      Parameters:
      num - the number of float values to allocate.
    • memCallocLong

      public static LongBuffer memCallocLong(int num)
      LongBuffer version of memCalloc(int, int).
      Parameters:
      num - the number of long values to allocate.
    • memCallocCLong

      public static CLongBuffer memCallocCLong(int num)
      CLongBuffer version of memCalloc(int, int).
      Parameters:
      num - the number of C long values to allocate.
    • memCallocDouble

      public static DoubleBuffer memCallocDouble(int num)
      DoubleBuffer version of memCalloc(int, int).
      Parameters:
      num - the number of double values to allocate.
    • memCallocPointer

      public static PointerBuffer memCallocPointer(int num)
      PointerBuffer version of memCalloc(int, int).
      Parameters:
      num - the number of pointer values to allocate.
    • nmemRealloc

      public static long nmemRealloc(long ptr, long size)
      Unsafe version of memRealloc(ByteBuffer, int). May return NULL if size is zero or the allocation failed.
    • nmemReallocChecked

      public static long nmemReallocChecked(long ptr, long size)
      Unsafe version of memRealloc(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 if size is zero.
      Throws:
      OutOfMemoryError - if the function failed to allocate the requested block of memory
    • memRealloc

      public static ByteBuffer memRealloc(@Nullable 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 of ptr does 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, unless size is 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 with memAlloc(int), memCalloc(int, int) or memRealloc(ByteBuffer, int). Alternatively, this can be a NULL pointer, in which case a new block is allocated (as if memAlloc(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 ptr or a new location
      Throws:
      OutOfMemoryError - if the function failed to allocate the requested block of memory. The memory block pointed to by argument ptr is not deallocated (it is still valid, and with its contents unchanged).
    • memRealloc

      public static CharBuffer memRealloc(@Nullable CharBuffer ptr, int size)
      CharBuffer version of memRealloc(ByteBuffer, int).
      Parameters:
      size - the number of char values to allocate.
    • memRealloc

      public static ShortBuffer memRealloc(@Nullable ShortBuffer ptr, int size)
      ShortBuffer version of memRealloc(ByteBuffer, int).
      Parameters:
      size - the number of short values to allocate.
    • memRealloc

      public static IntBuffer memRealloc(@Nullable IntBuffer ptr, int size)
      IntBuffer version of memRealloc(ByteBuffer, int).
      Parameters:
      size - the number of int values to allocate.
    • memRealloc

      public static LongBuffer memRealloc(@Nullable LongBuffer ptr, int size)
      LongBuffer version of memRealloc(ByteBuffer, int).
      Parameters:
      size - the number of long values to allocate.
    • memRealloc

      public static CLongBuffer memRealloc(@Nullable CLongBuffer ptr, int size)
      CLongBuffer version of memRealloc(ByteBuffer, int).
      Parameters:
      size - the number of C long values to allocate.
    • memRealloc

      public static FloatBuffer memRealloc(@Nullable FloatBuffer ptr, int size)
      FloatBuffer version of memRealloc(ByteBuffer, int).
      Parameters:
      size - the number of float values to allocate.
    • memRealloc

      public static DoubleBuffer memRealloc(@Nullable DoubleBuffer ptr, int size)
      DoubleBuffer version of memRealloc(ByteBuffer, int).
      Parameters:
      size - the number of double values to allocate.
    • memRealloc

      public static PointerBuffer memRealloc(@Nullable PointerBuffer ptr, int size)
      PointerBuffer version of memRealloc(ByteBuffer, int).
      Parameters:
      size - the number of pointer values to allocate.
    • nmemAlignedAlloc

      public static long nmemAlignedAlloc(long alignment, long size)
      Unsafe version of memAlignedAlloc(int, int). May return NULL if size is zero or the allocation failed.
    • nmemAlignedAllocChecked

      public static long nmemAlignedAllocChecked(long alignment, long size)
      Unsafe version of memAlignedAlloc(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 if size is zero.
      Throws:
      OutOfMemoryError - if the function failed to allocate the requested block of memory
    • memAlignedAlloc

      public static ByteBuffer memAlignedAlloc(int alignment, int size)
      The standard C aligned_alloc function.

      Allocate size bytes of uninitialized storage whose alignment is specified by alignment. The size parameter must be an integral multiple of alignment. Memory allocated with memAlignedAlloc() must be freed with memAlignedFree(ByteBuffer).

      Parameters:
      alignment - the alignment. Must be a power of two value and a multiple of sizeof(void *).
      size - the number of bytes to allocate. Must be a multiple of alignment.
    • nmemAlignedFree

      public static void nmemAlignedFree(long ptr)
      Unsafe version of memAlignedFree(ByteBuffer).
    • memAlignedFree

      public static void memAlignedFree(@Nullable ByteBuffer ptr)
      Frees a block of memory that was allocated with memAlignedAlloc(int, int). If ptr is NULL, 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_ALLOCATOR option 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_ALLOCATOR option has been set to true.

      Parameters:
      report - the report callback
      groupByStackTrace - how to aggregate the reported allocations
      groupByThread - if the reported allocations should be grouped by thread
    • memAddress0

      public static long memAddress0(Buffer buffer)
      Returns the memory address of the specified buffer. [INTERNAL USE ONLY]
      Parameters:
      buffer - the buffer
      Returns:
      the memory address
    • memAddress0

      public static long memAddress0(ByteBuffer buffer)
      ByteBuffer version of memAddress0(Buffer).
    • memAddress0

      public static long memAddress0(ShortBuffer buffer)
      ShortBuffer version of memAddress0(Buffer).
    • memAddress0

      public static long memAddress0(CharBuffer buffer)
      CharBuffer version of memAddress0(Buffer).
    • memAddress0

      public static long memAddress0(IntBuffer buffer)
      IntBuffer version of memAddress0(Buffer).
    • memAddress0

      public static long memAddress0(LongBuffer buffer)
      LongBuffer version of memAddress0(Buffer).
    • memAddress0

      public static long memAddress0(FloatBuffer buffer)
      FloatBuffer version of memAddress0(Buffer).
    • memAddress0

      public static long memAddress0(DoubleBuffer buffer)
      DoubleBuffer version of memAddress0(Buffer).
    • memAddress

      public static long memAddress(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(ByteBuffer buffer, int position)
      Returns the memory address at the specified position of the specified buffer.
      Parameters:
      buffer - the buffer
      position - the buffer position
      Returns:
      the memory address
      See Also:
    • memAddress

      public static long memAddress(ShortBuffer buffer)
      ShortBuffer version of memAddress(ByteBuffer).
    • memAddress

      public static long memAddress(ShortBuffer buffer, int position)
      ShortBuffer version of memAddress(ByteBuffer, int).
    • memAddress

      public static long memAddress(CharBuffer buffer)
      CharBuffer version of memAddress(ByteBuffer).
    • memAddress

      public static long memAddress(CharBuffer buffer, int position)
      CharBuffer version of memAddress(ByteBuffer, int).
    • memAddress

      public static long memAddress(IntBuffer buffer)
      IntBuffer version of memAddress(ByteBuffer).
    • memAddress

      public static long memAddress(IntBuffer buffer, int position)
      IntBuffer version of memAddress(ByteBuffer, int).
    • memAddress

      public static long memAddress(FloatBuffer buffer)
      FloatBuffer version of memAddress(ByteBuffer).
    • memAddress

      public static long memAddress(FloatBuffer buffer, int position)
      FloatBuffer version of memAddress(ByteBuffer, int).
    • memAddress

      public static long memAddress(LongBuffer buffer)
      LongBuffer version of memAddress(ByteBuffer).
    • memAddress

      public static long memAddress(LongBuffer buffer, int position)
      LongBuffer version of memAddress(ByteBuffer, int).
    • memAddress

      public static long memAddress(DoubleBuffer buffer)
      DoubleBuffer version of memAddress(ByteBuffer).
    • memAddress

      public static long memAddress(DoubleBuffer buffer, int position)
      DoubleBuffer version of memAddress(ByteBuffer, int).
    • memAddress

      public static long memAddress(Buffer buffer)
      Polymorphic version of memAddress(ByteBuffer).
    • memAddress

      public static long memAddress(CustomBuffer<?> buffer)
      CustomBuffer version of memAddress(ByteBuffer).
    • memAddress

      public static long memAddress(CustomBuffer<?> buffer, int position)
      CustomBuffer version of memAddress(ByteBuffer, int).
    • memAddressSafe

      public static long memAddressSafe(@Nullable ByteBuffer buffer)
      Null-safe version of memAddress(ByteBuffer). Returns NULL if the specified buffer is null.
    • memAddressSafe

      public static long memAddressSafe(@Nullable ShortBuffer buffer)
      ShortBuffer version of memAddressSafe(ByteBuffer).
    • memAddressSafe

      public static long memAddressSafe(@Nullable CharBuffer buffer)
      CharBuffer version of memAddressSafe(ByteBuffer).
    • memAddressSafe

      public static long memAddressSafe(@Nullable IntBuffer buffer)
      IntBuffer version of memAddressSafe(ByteBuffer).
    • memAddressSafe

      public static long memAddressSafe(@Nullable FloatBuffer buffer)
      FloatBuffer version of memAddressSafe(ByteBuffer).
    • memAddressSafe

      public static long memAddressSafe(@Nullable LongBuffer buffer)
      LongBuffer version of memAddressSafe(ByteBuffer).
    • memAddressSafe

      public static long memAddressSafe(@Nullable DoubleBuffer buffer)
      DoubleBuffer version of memAddressSafe(ByteBuffer).
    • memAddressSafe

      public static long memAddressSafe(@Nullable Pointer pointer)
      Pointer version of memAddressSafe(ByteBuffer).
    • memByteBuffer

      public static 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 native ByteOrder.
      Parameters:
      address - the starting memory address
      capacity - the buffer capacity
      Returns:
      the new ByteBuffer
    • memByteBufferSafe

      public static @Nullable ByteBuffer memByteBufferSafe(long address, int capacity)
      Like memByteBuffer, but returns null if address is NULL.
    • memByteBuffer

      public static ByteBuffer memByteBuffer(ShortBuffer buffer)
      Creates a ByteBuffer instance as a view of the specified ShortBuffer between its current position and limit.

      This operation is the inverse of ByteBuffer.asShortBuffer(). The returned ByteBuffer instance will be set to the native ByteOrder.

      Parameters:
      buffer - the source buffer
      Returns:
      the ByteBuffer view
    • memByteBuffer

      public static ByteBuffer memByteBuffer(CharBuffer buffer)
      Creates a ByteBuffer instance as a view of the specified CharBuffer between its current position and limit.

      This operation is the inverse of ByteBuffer.asCharBuffer(). The returned ByteBuffer instance will be set to the native ByteOrder.

      Parameters:
      buffer - the source buffer
      Returns:
      the ByteBuffer view
    • memByteBuffer

      public static ByteBuffer memByteBuffer(IntBuffer buffer)
      Creates a ByteBuffer instance as a view of the specified IntBuffer between its current position and limit.

      This operation is the inverse of ByteBuffer.asIntBuffer(). The returned ByteBuffer instance will be set to the native ByteOrder.

      Parameters:
      buffer - the source buffer
      Returns:
      the ByteBuffer view
    • memByteBuffer

      public static ByteBuffer memByteBuffer(LongBuffer buffer)
      Creates a ByteBuffer instance as a view of the specified LongBuffer between its current position and limit.

      This operation is the inverse of ByteBuffer.asLongBuffer(). The returned ByteBuffer instance will be set to the native ByteOrder.

      Parameters:
      buffer - the source buffer
      Returns:
      the ByteBuffer view
    • memByteBuffer

      public static ByteBuffer memByteBuffer(FloatBuffer buffer)
      Creates a ByteBuffer instance as a view of the specified FloatBuffer between its current position and limit.

      This operation is the inverse of ByteBuffer.asFloatBuffer(). The returned ByteBuffer instance will be set to the native ByteOrder.

      Parameters:
      buffer - the source buffer
      Returns:
      the ByteBuffer view
    • memByteBuffer

      public static ByteBuffer memByteBuffer(DoubleBuffer buffer)
      Creates a ByteBuffer instance as a view of the specified DoubleBuffer between its current position and limit.

      This operation is the inverse of ByteBuffer.asDoubleBuffer(). The returned ByteBuffer instance will be set to the native ByteOrder.

      Parameters:
      buffer - the source buffer
      Returns:
      the ByteBuffer view
    • memByteBuffer

      public static ByteBuffer memByteBuffer(CustomBuffer<?> buffer)
      Creates a ByteBuffer instance as a view of the specified CustomBuffer between its current position and limit.

      The returned ByteBuffer instance will be set to the native ByteOrder.

      Parameters:
      buffer - the source buffer
      Returns:
      the ByteBuffer view
    • memByteBuffer

      public static <T extends Struct<T>> ByteBuffer memByteBuffer(T value)
      Creates a ByteBuffer instance as a view of the specified Struct.

      The returned ByteBuffer instance will be set to the native ByteOrder.

      Parameters:
      value - the struct value
      Returns:
      the ByteBuffer view
    • memShortBuffer

      public static ShortBuffer memShortBuffer(long address, int capacity)
      Creates a new direct ShortBuffer that starts at the specified memory address and has the specified capacity.

      The address specified must be aligned to 2 bytes. If not, use memByteBuffer(address, capacity * 2).asShortBuffer().

      Parameters:
      address - the starting memory address
      capacity - the buffer capacity
      Returns:
      the new ShortBuffer
    • memShortBufferSafe

      public static @Nullable ShortBuffer memShortBufferSafe(long address, int capacity)
      Like memShortBuffer(long, int), but returns null if address is NULL.
    • memCharBuffer

      public static CharBuffer memCharBuffer(long address, int capacity)
      Creates a new direct CharBuffer that starts at the specified memory address and has the specified capacity.

      The address specified must be aligned to 2 bytes. If not, use memByteBuffer(address, capacity * 2).asCharBuffer().

      Parameters:
      address - the starting memory address
      capacity - the buffer capacity
      Returns:
      the new CharBuffer
    • memCharBufferSafe

      public static @Nullable CharBuffer memCharBufferSafe(long address, int capacity)
      Like memCharBuffer(long, int), but returns null if address is NULL.
    • memIntBuffer

      public static IntBuffer memIntBuffer(long address, int capacity)
      Creates a new direct IntBuffer that starts at the specified memory address and has the specified capacity.

      The address specified must be aligned to 4 bytes. If not, use memByteBuffer(address, capacity * 4).asIntBuffer().

      Parameters:
      address - the starting memory address
      capacity - the buffer capacity
      Returns:
      the new IntBuffer
    • memIntBufferSafe

      public static @Nullable IntBuffer memIntBufferSafe(long address, int capacity)
      Like memIntBuffer(long, int), but returns null if address is NULL.
    • memLongBuffer

      public static LongBuffer memLongBuffer(long address, int capacity)
      Creates a new direct LongBuffer that starts at the specified memory address and has the specified capacity.

      The address specified must be aligned to 8 bytes. If not, use memByteBuffer(address, capacity * 8).asLongBuffer().

      Parameters:
      address - the starting memory address
      capacity - the buffer capacity
      Returns:
      the new LongBuffer
    • memLongBufferSafe

      public static @Nullable LongBuffer memLongBufferSafe(long address, int capacity)
      Like memLongBuffer(long, int), but returns null if address is NULL.
    • memCLongBuffer

      public static CLongBuffer memCLongBuffer(long address, int capacity)
      Creates a new direct CLongBuffer that starts at the specified memory address and has the specified capacity.

      The address specified must be aligned to 8 bytes. If not, use memByteBuffer(address, capacity * 8).asLongBuffer().

      Parameters:
      address - the starting memory address
      capacity - the buffer capacity
      Returns:
      the new CLongBuffer
    • memCLongBufferSafe

      public static @Nullable CLongBuffer memCLongBufferSafe(long address, int capacity)
      Like memCLongBuffer(long, int), but returns null if address is NULL.
    • memFloatBuffer

      public static FloatBuffer memFloatBuffer(long address, int capacity)
      Creates a new direct FloatBuffer that starts at the specified memory address and has the specified capacity.

      The address specified must be aligned to 4 bytes. If not, use memByteBuffer(address, capacity * 4).asFloatBuffer().

      Parameters:
      address - the starting memory address
      capacity - the buffer capacity
      Returns:
      the new FloatBuffer
    • memFloatBufferSafe

      public static @Nullable FloatBuffer memFloatBufferSafe(long address, int capacity)
      Like memFloatBuffer(long, int), but returns null if address is NULL.
    • memDoubleBuffer

      public static DoubleBuffer memDoubleBuffer(long address, int capacity)
      Creates a new direct DoubleBuffer that starts at the specified memory address and has the specified capacity.

      The address specified must be aligned to 8 bytes. If not, use memByteBuffer(address, capacity * 8).asDoubleBuffer().

      Parameters:
      address - the starting memory address
      capacity - the buffer capacity
      Returns:
      the new DoubleBuffer
    • memDoubleBufferSafe

      public static @Nullable DoubleBuffer memDoubleBufferSafe(long address, int capacity)
      Like memDoubleBuffer(long, int), but returns null if address is NULL.
    • 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 address specified must be aligned to the pointer size. If not, use PointerBuffer.create(memByteBuffer(address, capacity * POINTER_SIZE)).

      Parameters:
      address - the starting memory address
      capacity - the buffer capacity
      Returns:
      the new PointerBuffer
    • memPointerBufferSafe

      public static @Nullable PointerBuffer memPointerBufferSafe(long address, int capacity)
      Like memPointerBuffer(long, int), but returns null if address is NULL.
    • memDuplicate

      public static ByteBuffer memDuplicate(ByteBuffer buffer)
      Duplicates the specified buffer. The returned buffer will have the same ByteOrder as 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).

      This method does not support buffers created from FFM MemorySegment instances.

      Parameters:
      buffer - the buffer to duplicate
      Returns:
      the duplicated buffer
    • memDuplicate

      public static ShortBuffer memDuplicate(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).

      This method does not support buffers created from FFM MemorySegment instances.

      Parameters:
      buffer - the buffer to duplicate
      Returns:
      the duplicated buffer
    • memDuplicate

      public static CharBuffer memDuplicate(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).

      This method does not support buffers created from FFM MemorySegment instances.

      Parameters:
      buffer - the buffer to duplicate
      Returns:
      the duplicated buffer
    • memDuplicate

      public static IntBuffer memDuplicate(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).

      This method does not support buffers created from FFM MemorySegment instances.

      Parameters:
      buffer - the buffer to duplicate
      Returns:
      the duplicated buffer
    • memDuplicate

      public static LongBuffer memDuplicate(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).

      This method does not support buffers created from FFM MemorySegment instances.

      Parameters:
      buffer - the buffer to duplicate
      Returns:
      the duplicated buffer
    • memDuplicate

      public static FloatBuffer memDuplicate(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).

      This method does not support buffers created from FFM MemorySegment instances.

      Parameters:
      buffer - the buffer to duplicate
      Returns:
      the duplicated buffer
    • memDuplicate

      public static DoubleBuffer memDuplicate(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).

      This method does not support buffers created from FFM MemorySegment instances.

      Parameters:
      buffer - the buffer to duplicate
      Returns:
      the duplicated buffer
    • memSlice

      public static ByteBuffer memSlice(ByteBuffer buffer)
      Slices the specified buffer. The returned buffer will have the same ByteOrder as 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).

      This method does not support buffers created from FFM MemorySegment instances.

      Parameters:
      buffer - the buffer to slice
      Returns:
      the sliced buffer
    • memSlice

      public static ShortBuffer memSlice(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).

      This method does not support buffers created from FFM MemorySegment instances.

      Parameters:
      buffer - the buffer to slice
      Returns:
      the sliced buffer
    • memSlice

      public static CharBuffer memSlice(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).

      This method does not support buffers created from FFM MemorySegment instances.

      Parameters:
      buffer - the buffer to slice
      Returns:
      the sliced buffer
    • memSlice

      public static IntBuffer memSlice(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).

      This method does not support buffers created from FFM MemorySegment instances.

      Parameters:
      buffer - the buffer to slice
      Returns:
      the sliced buffer
    • memSlice

      public static LongBuffer memSlice(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).

      This method does not support buffers created from FFM MemorySegment instances.

      Parameters:
      buffer - the buffer to slice
      Returns:
      the sliced buffer
    • memSlice

      public static FloatBuffer memSlice(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).

      This method does not support buffers created from FFM MemorySegment instances.

      Parameters:
      buffer - the buffer to slice
      Returns:
      the sliced buffer
    • memSlice

      public static DoubleBuffer memSlice(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).

      This method does not support buffers created from FFM MemorySegment instances.

      Parameters:
      buffer - the buffer to slice
      Returns:
      the sliced buffer
    • memSlice

      public static ByteBuffer memSlice(ByteBuffer buffer, int offset, int length)
      Returns a slice of the specified buffer between (buffer.position() + offset) and (buffer.position() + offset + length). The returned buffer will have the same ByteOrder as the original buffer.

      The position and limit of the original buffer are preserved after a call to this method.

      This method does not support buffers created from FFM MemorySegment instances.

      Parameters:
      buffer - the buffer to slice
      offset - the slice offset, it must be ≤ buffer.remaining()
      length - the slice length, it must be ≤ buffer.capacity() - (buffer.position() + offset)
      Returns:
      the sliced buffer
    • memSlice

      public static ShortBuffer memSlice(ShortBuffer buffer, int offset, int length)
      Returns a slice of the specified buffer between (buffer.position() + offset) and (buffer.position() + offset + length).

      The position and limit of the original buffer are preserved after a call to this method.

      This method does not support buffers created from FFM MemorySegment instances.

      Parameters:
      buffer - the buffer to slice
      offset - the slice offset, it must be ≤ buffer.remaining()
      length - the slice length, it must be ≤ buffer.capacity() - (buffer.position() + offset)
      Returns:
      the sliced buffer
    • memSlice

      public static CharBuffer memSlice(CharBuffer buffer, int offset, int length)
      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.

      This method does not support buffers created from FFM MemorySegment instances.

      Parameters:
      buffer - the buffer to slice
      offset - the slice offset, it must be ≤ buffer.remaining()
      length - the slice length, it must be ≤ buffer.capacity() - (buffer.position() + offset)
      Returns:
      the sliced buffer
    • memSlice

      public static IntBuffer memSlice(IntBuffer buffer, int offset, int length)
      Returns a slice of the specified buffer between (buffer.position() + offset) and (buffer.position() + offset + length).

      The position and limit of the original buffer are preserved after a call to this method.

      This method does not support buffers created from FFM MemorySegment instances.

      Parameters:
      buffer - the buffer to slice
      offset - the slice offset, it must be ≤ buffer.remaining()
      length - the slice length, it must be ≤ buffer.capacity() - (buffer.position() + offset)
      Returns:
      the sliced buffer
    • memSlice

      public static LongBuffer memSlice(LongBuffer buffer, int offset, int length)
      Returns a slice of the specified buffer between (buffer.position() + offset) and (buffer.position() + offset + length).

      The position and limit of the original buffer are preserved after a call to this method.

      This method does not support buffers created from FFM MemorySegment instances.

      Parameters:
      buffer - the buffer to slice
      offset - the slice offset, it must be ≤ buffer.remaining()
      length - the slice length, it must be ≤ buffer.capacity() - (buffer.position() + offset)
      Returns:
      the sliced buffer
    • memSlice

      public static FloatBuffer memSlice(FloatBuffer buffer, int offset, int length)
      Returns a slice of the specified buffer between (buffer.position() + offset) and (buffer.position() + offset + length).

      The position and limit of the original buffer are preserved after a call to this method.

      This method does not support buffers created from FFM MemorySegment instances.

      Parameters:
      buffer - the buffer to slice
      offset - the slice offset, it must be ≤ buffer.remaining()
      length - the slice length, it must be ≤ buffer.capacity() - (buffer.position() + offset)
      Returns:
      the sliced buffer
    • memSlice

      public static DoubleBuffer memSlice(DoubleBuffer buffer, int offset, int length)
      Returns a slice of the specified buffer between (buffer.position() + offset) and (buffer.position() + offset + length).

      The position and limit of the original buffer are preserved after a call to this method.

      This method does not support buffers created from FFM MemorySegment instances.

      Parameters:
      buffer - the buffer to slice
      offset - the slice offset, it must be ≤ buffer.remaining()
      length - 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 length)
      Returns a slice of the specified buffer between (buffer.position() + offset) and (buffer.position() + offset + length).

      The position and limit of the original buffer are preserved after a call to this method.

      Parameters:
      buffer - the buffer to slice
      offset - the slice offset, it must be ≤ buffer.remaining()
      length - the slice length, it must be ≤ buffer.capacity() - (buffer.position() + offset)
      Returns:
      the sliced buffer
    • memSet

      public static void memSet(ByteBuffer ptr, int value)
      Sets all bytes in a specified block of memory to a fixed value (usually zero).
      Parameters:
      ptr - the starting memory address
      value - the value to set (memSet will convert it to unsigned byte)
    • memSet

      public static void memSet(ShortBuffer ptr, int value)
      Sets all bytes in a specified block of memory to a fixed value (usually zero).
      Parameters:
      ptr - the starting memory address
      value - the value to set (memSet will convert it to unsigned byte)
    • memSet

      public static void memSet(CharBuffer ptr, int value)
      Sets all bytes in a specified block of memory to a fixed value (usually zero).
      Parameters:
      ptr - the starting memory address
      value - the value to set (memSet will convert it to unsigned byte)
    • memSet

      public static void memSet(IntBuffer ptr, int value)
      Sets all bytes in a specified block of memory to a fixed value (usually zero).
      Parameters:
      ptr - the starting memory address
      value - the value to set (memSet will convert it to unsigned byte)
    • memSet

      public static void memSet(LongBuffer ptr, int value)
      Sets all bytes in a specified block of memory to a fixed value (usually zero).
      Parameters:
      ptr - the starting memory address
      value - the value to set (memSet will convert it to unsigned byte)
    • memSet

      public static void memSet(FloatBuffer ptr, int value)
      Sets all bytes in a specified block of memory to a fixed value (usually zero).
      Parameters:
      ptr - the starting memory address
      value - the value to set (memSet will convert it to unsigned byte)
    • memSet

      public static void memSet(DoubleBuffer ptr, int value)
      Sets all bytes in a specified block of memory to a fixed value (usually zero).
      Parameters:
      ptr - the starting memory address
      value - 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 address
      value - the value to set (memSet will convert it to unsigned byte)
    • memSet

      public static <T extends Struct<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 struct type
      Parameters:
      ptr - the starting memory address
      value - the value to set (memSet will convert it to unsigned byte)
    • memCopy

      public static void memCopy(ByteBuffer src, ByteBuffer dst)
      Sets all bytes in a specified block of memory to a copy of another block.
      Parameters:
      src - the source memory address
      dst - the destination memory address
    • memCopy

      public static void memCopy(ShortBuffer src, ShortBuffer dst)
      Sets all bytes in a specified block of memory to a copy of another block.
      Parameters:
      src - the source memory address
      dst - the destination memory address
    • memCopy

      public static void memCopy(CharBuffer src, CharBuffer dst)
      Sets all bytes in a specified block of memory to a copy of another block.
      Parameters:
      src - the source memory address
      dst - the destination memory address
    • memCopy

      public static void memCopy(IntBuffer src, IntBuffer dst)
      Sets all bytes in a specified block of memory to a copy of another block.
      Parameters:
      src - the source memory address
      dst - the destination memory address
    • memCopy

      public static void memCopy(LongBuffer src, LongBuffer dst)
      Sets all bytes in a specified block of memory to a copy of another block.
      Parameters:
      src - the source memory address
      dst - the destination memory address
    • memCopy

      public static void memCopy(FloatBuffer src, FloatBuffer dst)
      Sets all bytes in a specified block of memory to a copy of another block.
      Parameters:
      src - the source memory address
      dst - the destination memory address
    • memCopy

      public static void memCopy(DoubleBuffer src, DoubleBuffer dst)
      Sets all bytes in a specified block of memory to a copy of another block.
      Parameters:
      src - the source memory address
      dst - 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 address
      dst - the destination memory address
    • memCopy

      public static <T extends Struct<T>> 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 struct
      dst - the destination struct
    • memCopy

      public static void memCopy(byte[] src, ByteBuffer dst)
      Copies the source array to the current position of the destination buffer.
      Parameters:
      src - the source array
      dst - the destination buffer
    • memCopy

      public static void memCopy(char[] src, ByteBuffer dst)
      Copies the source array to the current position of the destination buffer.
      Parameters:
      src - the source array
      dst - the destination buffer
    • memCopy

      public static void memCopy(char[] src, CharBuffer dst)
      Copies the source array to the current position of the destination buffer.
      Parameters:
      src - the source array
      dst - the destination buffer
    • memCopy

      public static void memCopy(short[] src, ByteBuffer dst)
      Copies the source array to the current position of the destination buffer.
      Parameters:
      src - the source array
      dst - the destination buffer
    • memCopy

      public static void memCopy(short[] src, ShortBuffer dst)
      Copies the source array to the current position of the destination buffer.
      Parameters:
      src - the source array
      dst - the destination buffer
    • memCopy

      public static void memCopy(int[] src, ByteBuffer dst)
      Copies the source array to the current position of the destination buffer.
      Parameters:
      src - the source array
      dst - the destination buffer
    • memCopy

      public static void memCopy(int[] src, IntBuffer dst)
      Copies the source array to the current position of the destination buffer.
      Parameters:
      src - the source array
      dst - the destination buffer
    • memCopy

      public static void memCopy(long[] src, ByteBuffer dst)
      Copies the source array to the current position of the destination buffer.
      Parameters:
      src - the source array
      dst - the destination buffer
    • memCopy

      public static void memCopy(long[] src, LongBuffer dst)
      Copies the source array to the current position of the destination buffer.
      Parameters:
      src - the source array
      dst - the destination buffer
    • memCopy

      public static void memCopy(float[] src, ByteBuffer dst)
      Copies the source array to the current position of the destination buffer.
      Parameters:
      src - the source array
      dst - the destination buffer
    • memCopy

      public static void memCopy(float[] src, FloatBuffer dst)
      Copies the source array to the current position of the destination buffer.
      Parameters:
      src - the source array
      dst - the destination buffer
    • memCopy

      public static void memCopy(double[] src, ByteBuffer dst)
      Copies the source array to the current position of the destination buffer.
      Parameters:
      src - the source array
      dst - the destination buffer
    • memCopy

      public static void memCopy(double[] src, DoubleBuffer dst)
      Copies the source array to the current position of the destination buffer.
      Parameters:
      src - the source array
      dst - the destination buffer
    • memCopy

      public static void memCopy(byte[] src, ByteBuffer dst, int offset, int size)
      Copies size elements from the source array, starting at offset, to the current position of the destination buffer.
      Parameters:
      src - the source array
      dst - the destination buffer
      offset - the offset into the source array
      size - the number of elements to copy
    • memCopy

      public static void memCopy(char[] src, ByteBuffer dst, int offset, int size)
      Copies size elements from the source array, starting at offset, to the current position of the destination buffer.
      Parameters:
      src - the source array
      dst - the destination buffer
      offset - the offset into the source array
      size - the number of elements to copy
    • memCopy

      public static void memCopy(char[] src, CharBuffer dst, int offset, int size)
      Copies size elements from the source array, starting at offset, to the current position of the destination buffer.
      Parameters:
      src - the source array
      dst - the destination buffer
      offset - the offset into the source array
      size - the number of elements to copy
    • memCopy

      public static void memCopy(short[] src, ByteBuffer dst, int offset, int size)
      Copies size elements from the source array, starting at offset, to the current position of the destination buffer.
      Parameters:
      src - the source array
      dst - the destination buffer
      offset - the offset into the source array
      size - the number of elements to copy
    • memCopy

      public static void memCopy(short[] src, ShortBuffer dst, int offset, int size)
      Copies size elements from the source array, starting at offset, to the current position of the destination buffer.
      Parameters:
      src - the source array
      dst - the destination buffer
      offset - the offset into the source array
      size - the number of elements to copy
    • memCopy

      public static void memCopy(int[] src, ByteBuffer dst, int offset, int size)
      Copies size elements from the source array, starting at offset, to the current position of the destination buffer.
      Parameters:
      src - the source array
      dst - the destination buffer
      offset - the offset into the source array
      size - the number of elements to copy
    • memCopy

      public static void memCopy(int[] src, IntBuffer dst, int offset, int size)
      Copies size elements from the source array, starting at offset, to the current position of the destination buffer.
      Parameters:
      src - the source array
      dst - the destination buffer
      offset - the offset into the source array
      size - the number of elements to copy
    • memCopy

      public static void memCopy(long[] src, ByteBuffer dst, int offset, int size)
      Copies size elements from the source array, starting at offset, to the current position of the destination buffer.
      Parameters:
      src - the source array
      dst - the destination buffer
      offset - the offset into the source array
      size - the number of elements to copy
    • memCopy

      public static void memCopy(long[] src, LongBuffer dst, int offset, int size)
      Copies size elements from the source array, starting at offset, to the current position of the destination buffer.
      Parameters:
      src - the source array
      dst - the destination buffer
      offset - the offset into the source array
      size - the number of elements to copy
    • memCopy

      public static void memCopy(float[] src, ByteBuffer dst, int offset, int size)
      Copies size elements from the source array, starting at offset, to the current position of the destination buffer.
      Parameters:
      src - the source array
      dst - the destination buffer
      offset - the offset into the source array
      size - the number of elements to copy
    • memCopy

      public static void memCopy(float[] src, FloatBuffer dst, int offset, int size)
      Copies size elements from the source array, starting at offset, to the current position of the destination buffer.
      Parameters:
      src - the source array
      dst - the destination buffer
      offset - the offset into the source array
      size - the number of elements to copy
    • memCopy

      public static void memCopy(double[] src, ByteBuffer dst, int offset, int size)
      Copies size elements from the source array, starting at offset, to the current position of the destination buffer.
      Parameters:
      src - the source array
      dst - the destination buffer
      offset - the offset into the source array
      size - the number of elements to copy
    • memCopy

      public static void memCopy(double[] src, DoubleBuffer dst, int offset, int size)
      Copies size elements from the source array, starting at offset, to the current position of the destination buffer.
      Parameters:
      src - the source array
      dst - the destination buffer
      offset - the offset into the source array
      size - the number of elements to copy
    • memCopy

      public static void memCopy(ByteBuffer src, byte[] dst)
      Copies the source buffer to the destination array.
      Parameters:
      src - the source buffer
      dst - the destination array
    • memCopy

      public static void memCopy(ByteBuffer src, char[] dst)
      Copies the source buffer to the destination array.
      Parameters:
      src - the source buffer
      dst - the destination array
    • memCopy

      public static void memCopy(CharBuffer src, char[] dst)
      Copies the source buffer to the destination array.
      Parameters:
      src - the source buffer
      dst - the destination array
    • memCopy

      public static void memCopy(ByteBuffer src, short[] dst)
      Copies the source buffer to the destination array.
      Parameters:
      src - the source buffer
      dst - the destination array
    • memCopy

      public static void memCopy(ShortBuffer src, short[] dst)
      Copies the source buffer to the destination array.
      Parameters:
      src - the source buffer
      dst - the destination array
    • memCopy

      public static void memCopy(ByteBuffer src, int[] dst)
      Copies the source buffer to the destination array.
      Parameters:
      src - the source buffer
      dst - the destination array
    • memCopy

      public static void memCopy(IntBuffer src, int[] dst)
      Copies the source buffer to the destination array.
      Parameters:
      src - the source buffer
      dst - the destination array
    • memCopy

      public static void memCopy(ByteBuffer src, long[] dst)
      Copies the source buffer to the destination array.
      Parameters:
      src - the source buffer
      dst - the destination array
    • memCopy

      public static void memCopy(LongBuffer src, long[] dst)
      Copies the source buffer to the destination array.
      Parameters:
      src - the source buffer
      dst - the destination array
    • memCopy

      public static void memCopy(ByteBuffer src, float[] dst)
      Copies the source buffer to the destination array.
      Parameters:
      src - the source buffer
      dst - the destination array
    • memCopy

      public static void memCopy(FloatBuffer src, float[] dst)
      Copies the source buffer to the destination array.
      Parameters:
      src - the source buffer
      dst - the destination array
    • memCopy

      public static void memCopy(ByteBuffer src, double[] dst)
      Copies the source buffer to the destination array.
      Parameters:
      src - the source buffer
      dst - the destination array
    • memCopy

      public static void memCopy(DoubleBuffer src, double[] dst)
      Copies the source buffer to the destination array.
      Parameters:
      src - the source buffer
      dst - the destination array
    • memCopy

      public static void memCopy(ByteBuffer src, byte[] dst, int offset, int size)
      Copies size elements from the source buffer to the destination array, starting at offset.
      Parameters:
      src - the source buffer
      dst - the destination array
      offset - the offset into the destination array
      size - the number of elements to copy
    • memCopy

      public static void memCopy(ByteBuffer src, char[] dst, int offset, int size)
      Copies size elements from the source buffer to the destination array, starting at offset.
      Parameters:
      src - the source buffer
      dst - the destination array
      offset - the offset into the destination array
      size - the number of elements to copy
    • memCopy

      public static void memCopy(CharBuffer src, char[] dst, int offset, int size)
      Copies size elements from the source buffer to the destination array, starting at offset.
      Parameters:
      src - the source buffer
      dst - the destination array
      offset - the offset into the destination array
      size - the number of elements to copy
    • memCopy

      public static void memCopy(ByteBuffer src, short[] dst, int offset, int size)
      Copies size elements from the source buffer to the destination array, starting at offset.
      Parameters:
      src - the source buffer
      dst - the destination array
      offset - the offset into the destination array
      size - the number of elements to copy
    • memCopy

      public static void memCopy(ShortBuffer src, short[] dst, int offset, int size)
      Copies size elements from the source buffer to the destination array, starting at offset.
      Parameters:
      src - the source buffer
      dst - the destination array
      offset - the offset into the destination array
      size - the number of elements to copy
    • memCopy

      public static void memCopy(ByteBuffer src, int[] dst, int offset, int size)
      Copies size elements from the source buffer to the destination array, starting at offset.
      Parameters:
      src - the source buffer
      dst - the destination array
      offset - the offset into the destination array
      size - the number of elements to copy
    • memCopy

      public static void memCopy(IntBuffer src, int[] dst, int offset, int size)
      Copies size elements from the source buffer to the destination array, starting at offset.
      Parameters:
      src - the source buffer
      dst - the destination array
      offset - the offset into the destination array
      size - the number of elements to copy
    • memCopy

      public static void memCopy(ByteBuffer src, long[] dst, int offset, int size)
      Copies size elements from the source buffer to the destination array, starting at offset.
      Parameters:
      src - the source buffer
      dst - the destination array
      offset - the offset into the destination array
      size - the number of elements to copy
    • memCopy

      public static void memCopy(LongBuffer src, long[] dst, int offset, int size)
      Copies size elements from the source buffer to the destination array, starting at offset.
      Parameters:
      src - the source buffer
      dst - the destination array
      offset - the offset into the destination array
      size - the number of elements to copy
    • memCopy

      public static void memCopy(ByteBuffer src, float[] dst, int offset, int size)
      Copies size elements from the source buffer to the destination array, starting at offset.
      Parameters:
      src - the source buffer
      dst - the destination array
      offset - the offset into the destination array
      size - the number of elements to copy
    • memCopy

      public static void memCopy(FloatBuffer src, float[] dst, int offset, int size)
      Copies size elements from the source buffer to the destination array, starting at offset.
      Parameters:
      src - the source buffer
      dst - the destination array
      offset - the offset into the destination array
      size - the number of elements to copy
    • memCopy

      public static void memCopy(ByteBuffer src, double[] dst, int offset, int size)
      Copies size elements from the source buffer to the destination array, starting at offset.
      Parameters:
      src - the source buffer
      dst - the destination array
      offset - the offset into the destination array
      size - the number of elements to copy
    • memCopy

      public static void memCopy(DoubleBuffer src, double[] dst, int offset, int size)
      Copies size elements from the source buffer to the destination array, starting at offset.
      Parameters:
      src - the source buffer
      dst - the destination array
      offset - the offset into the destination array
      size - the number of elements to copy
    • 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 address
      value - 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 address
      dst - the destination memory address
      bytes - the number of bytes to copy
    • memCopy

      public static void memCopy(byte[] src, long dst)
    • memCopy

      public static void memCopy(char[] src, long dst)
    • memCopy

      public static void memCopy(short[] src, long dst)
    • memCopy

      public static void memCopy(int[] src, long dst)
    • memCopy

      public static void memCopy(long[] src, long dst)
    • memCopy

      public static void memCopy(float[] src, long dst)
    • memCopy

      public static void memCopy(double[] src, long dst)
    • memCopy

      public static void memCopy(byte[] src, long dst, int offset, int size)
    • memCopy

      public static void memCopy(char[] src, long dst, int offset, int size)
    • memCopy

      public static void memCopy(short[] src, long dst, int offset, int size)
    • memCopy

      public static void memCopy(int[] src, long dst, int offset, int size)
    • memCopy

      public static void memCopy(long[] src, long dst, int offset, int size)
    • memCopy

      public static void memCopy(float[] src, long dst, int offset, int size)
    • memCopy

      public static void memCopy(double[] src, long dst, int offset, int size)
    • memCopy

      public static void memCopy(long src, byte[] dst)
    • memCopy

      public static void memCopy(long src, char[] dst)
    • memCopy

      public static void memCopy(long src, short[] dst)
    • memCopy

      public static void memCopy(long src, int[] dst)
    • memCopy

      public static void memCopy(long src, long[] dst)
    • memCopy

      public static void memCopy(long src, float[] dst)
    • memCopy

      public static void memCopy(long src, double[] dst)
    • memCopy

      public static void memCopy(long src, byte[] dst, int offset, int size)
    • memCopy

      public static void memCopy(long src, char[] dst, int offset, int size)
    • memCopy

      public static void memCopy(long src, short[] dst, int offset, int size)
    • memCopy

      public static void memCopy(long src, int[] dst, int offset, int size)
    • memCopy

      public static void memCopy(long src, long[] dst, int offset, int size)
    • memCopy

      public static void memCopy(long src, float[] dst, int offset, int size)
    • memCopy

      public static void memCopy(long src, double[] dst, int offset, int size)
    • memGetBoolean

      public static boolean memGetBoolean(long ptr)
    • memGetByte

      public static byte memGetByte(long ptr)
    • memGetChar

      public static char memGetChar(long ptr)
    • memGetCharUnaligned

      public static char memGetCharUnaligned(long ptr)
    • memGetShort

      public static short memGetShort(long ptr)
    • memGetShortUnaligned

      public static short memGetShortUnaligned(long ptr)
    • memGetInt

      public static int memGetInt(long ptr)
    • memGetIntUnaligned

      public static int memGetIntUnaligned(long ptr)
    • memGetLong

      public static long memGetLong(long ptr)
    • memGetLongUnaligned

      public static long memGetLongUnaligned(long ptr)
    • memGetFloat

      public static float memGetFloat(long ptr)
    • memGetFloatUnaligned

      public static float memGetFloatUnaligned(long ptr)
    • memGetDouble

      public static double memGetDouble(long ptr)
    • memGetDoubleUnaligned

      public static double memGetDoubleUnaligned(long ptr)
    • memGetCLong

      public static long memGetCLong(long ptr)
    • memGetCLongUnaligned

      public static long memGetCLongUnaligned(long ptr)
    • memGetAddress

      public static long memGetAddress(long ptr)
    • memGetAddressUnaligned

      public static long memGetAddressUnaligned(long ptr)
    • memPutBoolean

      public static void memPutBoolean(long ptr, boolean value)
    • memPutByte

      public static void memPutByte(long ptr, byte value)
    • memPutChar

      public static void memPutChar(long ptr, char value)
    • memPutCharUnaligned

      public static void memPutCharUnaligned(long ptr, char value)
    • memPutShort

      public static void memPutShort(long ptr, short value)
    • memPutShortUnaligned

      public static void memPutShortUnaligned(long ptr, short value)
    • memPutInt

      public static void memPutInt(long ptr, int value)
    • memPutIntUnaligned

      public static void memPutIntUnaligned(long ptr, int value)
    • memPutLong

      public static void memPutLong(long ptr, long value)
    • memPutLongUnaligned

      public static void memPutLongUnaligned(long ptr, long value)
    • memPutFloat

      public static void memPutFloat(long ptr, float value)
    • memPutFloatUnaligned

      public static void memPutFloatUnaligned(long ptr, float value)
    • memPutDouble

      public static void memPutDouble(long ptr, double value)
    • memPutDoubleUnaligned

      public static void memPutDoubleUnaligned(long ptr, double value)
    • memPutCLong

      public static void memPutCLong(long ptr, long value)
    • memPutCLongUnaligned

      public static void memPutCLongUnaligned(long ptr, long value)
    • memPutAddress

      public static void memPutAddress(long ptr, long value)
    • memPutAddressUnaligned

      public static void memPutAddressUnaligned(long ptr, long value)
    • memGet

      public static byte memGet(ByteBuffer buffer, long offset)
    • memGet

      public static char memGet(CharBuffer buffer, long offset)
    • memGet

      public static short memGet(ShortBuffer buffer, long offset)
    • memGet

      public static int memGet(IntBuffer buffer, long offset)
    • memGet

      public static long memGet(LongBuffer buffer, long offset)
    • memGet

      public static float memGet(FloatBuffer buffer, long offset)
    • memGet

      public static double memGet(DoubleBuffer buffer, long offset)
    • memGetAtIndex

      public static char memGetAtIndex(CharBuffer buffer, int index)
    • memGetAtIndex

      public static short memGetAtIndex(ShortBuffer buffer, int index)
    • memGetAtIndex

      public static int memGetAtIndex(IntBuffer buffer, int index)
    • memGetAtIndex

      public static long memGetAtIndex(LongBuffer buffer, int index)
    • memGetAtIndex

      public static float memGetAtIndex(FloatBuffer buffer, int index)
    • memGetAtIndex

      public static double memGetAtIndex(DoubleBuffer buffer, int index)
    • memGetBoolean

      public static boolean memGetBoolean(ByteBuffer buffer, long offset)
    • memGetChar

      public static char memGetChar(ByteBuffer buffer, long offset)
    • memGetCharAtIndex

      public static char memGetCharAtIndex(ByteBuffer buffer, int index)
    • memGetCharUnaligned

      public static char memGetCharUnaligned(ByteBuffer buffer, long offset)
    • memGetCharUnalignedAtIndex

      public static char memGetCharUnalignedAtIndex(ByteBuffer buffer, int index)
    • memGetShort

      public static short memGetShort(ByteBuffer buffer, long offset)
    • memGetShortAtIndex

      public static short memGetShortAtIndex(ByteBuffer buffer, int index)
    • memGetShortUnaligned

      public static short memGetShortUnaligned(ByteBuffer buffer, long offset)
    • memGetShortUnalignedAtIndex

      public static short memGetShortUnalignedAtIndex(ByteBuffer buffer, int index)
    • memGetInt

      public static int memGetInt(ByteBuffer buffer, long offset)
    • memGetIntAtIndex

      public static int memGetIntAtIndex(ByteBuffer buffer, int index)
    • memGetIntUnaligned

      public static int memGetIntUnaligned(ByteBuffer buffer, long offset)
    • memGetIntUnalignedAtIndex

      public static int memGetIntUnalignedAtIndex(ByteBuffer buffer, int index)
    • memGetLong

      public static long memGetLong(ByteBuffer buffer, long offset)
    • memGetLongAtIndex

      public static long memGetLongAtIndex(ByteBuffer buffer, int index)
    • memGetLongUnaligned

      public static long memGetLongUnaligned(ByteBuffer buffer, long offset)
    • memGetLongUnalignedAtIndex

      public static long memGetLongUnalignedAtIndex(ByteBuffer buffer, int index)
    • memGetFloat

      public static float memGetFloat(ByteBuffer buffer, long offset)
    • memGetFloatAtIndex

      public static float memGetFloatAtIndex(ByteBuffer buffer, int index)
    • memGetFloatUnaligned

      public static float memGetFloatUnaligned(ByteBuffer buffer, long offset)
    • memGetFloatUnalignedAtIndex

      public static float memGetFloatUnalignedAtIndex(ByteBuffer buffer, int index)
    • memGetDouble

      public static double memGetDouble(ByteBuffer buffer, long offset)
    • memGetDoubleAtIndex

      public static double memGetDoubleAtIndex(ByteBuffer buffer, int index)
    • memGetDoubleUnaligned

      public static double memGetDoubleUnaligned(ByteBuffer buffer, long offset)
    • memGetDoubleUnalignedAtIndex

      public static double memGetDoubleUnalignedAtIndex(ByteBuffer buffer, int index)
    • memGetCLong

      public static long memGetCLong(ByteBuffer buffer, long offset)
    • memGetCLongAtIndex

      public static long memGetCLongAtIndex(ByteBuffer buffer, int index)
    • memGetCLongUnaligned

      public static long memGetCLongUnaligned(ByteBuffer buffer, long offset)
    • memGetCLongUnalignedAtIndex

      public static long memGetCLongUnalignedAtIndex(ByteBuffer buffer, int index)
    • memGetAddress

      public static long memGetAddress(ByteBuffer buffer, long offset)
    • memGetAddressAtIndex

      public static long memGetAddressAtIndex(ByteBuffer buffer, int index)
    • memGetAddressUnaligned

      public static long memGetAddressUnaligned(ByteBuffer buffer, long offset)
    • memGetAddressUnalignedAtIndex

      public static long memGetAddressUnalignedAtIndex(ByteBuffer buffer, int index)
    • memPut

      public static void memPut(ByteBuffer buffer, long offset, byte value)
    • memPut

      public static void memPut(CharBuffer buffer, long offset, char value)
    • memPut

      public static void memPut(ShortBuffer buffer, long offset, short value)
    • memPut

      public static void memPut(IntBuffer buffer, long offset, int value)
    • memPut

      public static void memPut(LongBuffer buffer, long offset, long value)
    • memPut

      public static void memPut(FloatBuffer buffer, long offset, float value)
    • memPut

      public static void memPut(DoubleBuffer buffer, long offset, double value)
    • memPutAtIndex

      public static void memPutAtIndex(CharBuffer buffer, int index, char value)
    • memPutAtIndex

      public static void memPutAtIndex(ShortBuffer buffer, int index, short value)
    • memPutAtIndex

      public static void memPutAtIndex(IntBuffer buffer, int index, int value)
    • memPutAtIndex

      public static void memPutAtIndex(LongBuffer buffer, int index, long value)
    • memPutAtIndex

      public static void memPutAtIndex(FloatBuffer buffer, int index, float value)
    • memPutAtIndex

      public static void memPutAtIndex(DoubleBuffer buffer, int index, double value)
    • memPutBoolean

      public static void memPutBoolean(ByteBuffer buffer, long offset, boolean value)
    • memPutChar

      public static void memPutChar(ByteBuffer buffer, long offset, char value)
    • memPutCharAtIndex

      public static void memPutCharAtIndex(ByteBuffer buffer, int index, char value)
    • memPutCharUnaligned

      public static void memPutCharUnaligned(ByteBuffer buffer, long offset, char value)
    • memPutCharUnalignedAtIndex

      public static void memPutCharUnalignedAtIndex(ByteBuffer buffer, int index, char value)
    • memPutShort

      public static void memPutShort(ByteBuffer buffer, long offset, short value)
    • memPutShortAtIndex

      public static void memPutShortAtIndex(ByteBuffer buffer, int index, short value)
    • memPutShortUnaligned

      public static void memPutShortUnaligned(ByteBuffer buffer, long offset, short value)
    • memPutShortUnalignedAtIndex

      public static void memPutShortUnalignedAtIndex(ByteBuffer buffer, int index, short value)
    • memPutInt

      public static void memPutInt(ByteBuffer buffer, long offset, int value)
    • memPutIntAtIndex

      public static void memPutIntAtIndex(ByteBuffer buffer, int index, int value)
    • memPutIntUnaligned

      public static void memPutIntUnaligned(ByteBuffer buffer, long offset, int value)
    • memPutIntUnalignedAtIndex

      public static void memPutIntUnalignedAtIndex(ByteBuffer buffer, int index, int value)
    • memPutLong

      public static void memPutLong(ByteBuffer buffer, long offset, long value)
    • memPutLongAtIndex

      public static void memPutLongAtIndex(ByteBuffer buffer, int index, long value)
    • memPutLongUnaligned

      public static void memPutLongUnaligned(ByteBuffer buffer, long offset, long value)
    • memPutLongUnalignedAtIndex

      public static void memPutLongUnalignedAtIndex(ByteBuffer buffer, int index, long value)
    • memPutFloat

      public static void memPutFloat(ByteBuffer buffer, long offset, float value)
    • memPutFloatAtIndex

      public static void memPutFloatAtIndex(ByteBuffer buffer, int index, float value)
    • memPutFloatUnaligned

      public static void memPutFloatUnaligned(ByteBuffer buffer, long offset, float value)
    • memPutFloatUnalignedAtIndex

      public static void memPutFloatUnalignedAtIndex(ByteBuffer buffer, int index, float value)
    • memPutDouble

      public static void memPutDouble(ByteBuffer buffer, long offset, double value)
    • memPutDoubleAtIndex

      public static void memPutDoubleAtIndex(ByteBuffer buffer, int index, double value)
    • memPutDoubleUnaligned

      public static void memPutDoubleUnaligned(ByteBuffer buffer, long offset, double value)
    • memPutDoubleUnalignedAtIndex

      public static void memPutDoubleUnalignedAtIndex(ByteBuffer buffer, int index, double value)
    • memPutCLong

      public static void memPutCLong(ByteBuffer buffer, long offset, long value)
    • memPutCLongAtIndex

      public static void memPutCLongAtIndex(ByteBuffer buffer, int index, long value)
    • memPutCLongUnaligned

      public static void memPutCLongUnaligned(ByteBuffer buffer, long offset, long value)
    • memPutCLongUnalignedAtIndex

      public static void memPutCLongUnalignedAtIndex(ByteBuffer buffer, int index, long value)
    • memPutAddress

      public static void memPutAddress(ByteBuffer buffer, long offset, long value)
    • memPutAddressAtIndex

      public static void memPutAddressAtIndex(ByteBuffer buffer, int index, long value)
    • memPutAddressUnaligned

      public static void memPutAddressUnaligned(ByteBuffer buffer, long offset, long value)
    • memPutAddressUnalignedAtIndex

      public static void memPutAddressUnalignedAtIndex(ByteBuffer buffer, int index, 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
    • memASCII

      public static ByteBuffer memASCII(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(Buffer).
      Throws:
      BufferOverflowException - if more than Integer.MAX_VALUE bytes are required to encode the text.
    • memASCIISafe

      public static @Nullable ByteBuffer memASCIISafe(@Nullable CharSequence text)
      Like memASCII, but returns null if text is null.
    • memASCII

      public static ByteBuffer memASCII(CharSequence text, boolean nullTerminated)
      Returns a ByteBuffer containing the specified text ASCII encoded and optionally null-terminated.
      Parameters:
      text - the text to encode
      nullTerminated - if true, the text will be terminated with a '\0'.
      Returns:
      the encoded text. The returned buffer must be deallocated manually with memFree(Buffer).
      Throws:
      BufferOverflowException - if more than Integer.MAX_VALUE bytes are required to encode the text.
    • memASCIISafe

      public static @Nullable ByteBuffer memASCIISafe(@Nullable CharSequence text, boolean nullTerminated)
      Like memASCII, but returns null if text is null.
    • memASCII

      public static int memASCII(CharSequence text, boolean nullTerminated, ByteBuffer target)
      Encodes and optionally null-terminates the specified text using ASCII encoding. The encoded text is stored in the specified ByteBuffer, at the current buffer position. The current buffer position is not modified by this operation.
      Parameters:
      text - the text to encode
      nullTerminated - if true, the text will be terminated with a '\0'
      target - the buffer where the encoded text should be stored
      Returns:
      the number of bytes of the encoded string
      Throws:
      BufferOverflowException - if more than target.remaining() bytes are required to encode the text.
    • memASCII

      public static int memASCII(CharSequence text, boolean nullTerminated, ByteBuffer target, int offset)
      Encodes and optionally null-terminates the specified text using ASCII encoding. The encoded text is stored in the specified ByteBuffer at the specified position offset. The current buffer position is not modified by this operation.
      Parameters:
      text - the text to encode
      nullTerminated - 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
      Throws:
      BufferOverflowException - if more than target.capacity() - offset bytes are required to encode the text.
    • memLengthASCII

      public static int memLengthASCII(CharSequence value, boolean nullTerminated)
      Returns the number of bytes required to encode the specified text in the ASCII encoding.
      Parameters:
      value - the text to encode
      nullTerminated - if true, add the number of bytes required for null-termination
      Returns:
      the number of bytes
      Throws:
      BufferOverflowException - if more than Integer.MAX_VALUE bytes are required to encode the text.
    • memUTF8

      public static ByteBuffer memUTF8(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(Buffer).
      Throws:
      BufferOverflowException - if more than Integer.MAX_VALUE bytes are required to encode the text.
    • memUTF8Safe

      public static @Nullable ByteBuffer memUTF8Safe(@Nullable CharSequence text)
      Like memUTF8, but returns null if text is null.
    • memUTF8

      public static ByteBuffer memUTF8(CharSequence text, boolean nullTerminated)
      Returns a ByteBuffer containing the specified text UTF-8 encoded and optionally null-terminated.
      Parameters:
      text - the text to encode
      nullTerminated - if true, the text will be terminated with a '\0'.
      Returns:
      the encoded text. The returned buffer must be deallocated manually with memFree(Buffer).
      Throws:
      BufferOverflowException - if more than Integer.MAX_VALUE bytes are required to encode the text.
    • memUTF8Safe

      public static @Nullable ByteBuffer memUTF8Safe(@Nullable CharSequence text, boolean nullTerminated)
      Like memUTF8, but returns null if text is null.
    • memUTF8

      public static int memUTF8(CharSequence text, boolean nullTerminated, ByteBuffer target)
      Encodes and optionally null-terminates the specified text using UTF-8 encoding. The encoded text is stored in the specified ByteBuffer, at the current buffer position. The current buffer position is not modified by this operation.
      Parameters:
      text - the text to encode
      nullTerminated - 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
      Throws:
      BufferOverflowException - if more than target.remaining bytes are required to encode the text.
    • memUTF8

      public static int memUTF8(CharSequence text, boolean nullTerminated, ByteBuffer target, int offset)
      Encodes and optionally null-terminates the specified text using UTF-8 encoding. The encoded text is stored in the specified ByteBuffer, at the specified position offset. The current buffer position is not modified by this operation.
      Parameters:
      text - the text to encode
      nullTerminated - if true, the text will be terminated with a '\0'.
      target - the buffer in which to store the encoded text
      offset - the buffer position to which the string will be encoded
      Returns:
      the number of bytes of the encoded string
      Throws:
      BufferOverflowException - if more than target.capacity() - offset bytes are required to encode the text.
    • memLengthUTF8

      public static int memLengthUTF8(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 encode
      nullTerminated - if true, add the number of bytes required for null-termination
      Returns:
      the number of bytes
      Throws:
      BufferOverflowException - if more than Integer.MAX_VALUE bytes are required to encode the text.
    • memUTF16

      public static ByteBuffer memUTF16(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(Buffer).
      Throws:
      BufferOverflowException - if more than Integer.MAX_VALUE bytes are required to encode the text.
    • memUTF16Safe

      public static @Nullable ByteBuffer memUTF16Safe(@Nullable CharSequence text)
      Like memUTF16, but returns null if text is null.
    • memUTF16

      public static ByteBuffer memUTF16(CharSequence text, boolean nullTerminated)
      Returns a ByteBuffer containing the specified text UTF-16 encoded and optionally null-terminated.
      Parameters:
      text - the text to encode
      nullTerminated - if true, the text will be terminated with a '\0'.
      Returns:
      the encoded text. The returned buffer must be deallocated manually with memFree(Buffer).
      Throws:
      BufferOverflowException - if more than Integer.MAX_VALUE bytes are required to encode the text.
    • memUTF16Safe

      public static @Nullable ByteBuffer memUTF16Safe(@Nullable CharSequence text, boolean nullTerminated)
      Like memUTF16, but returns null if text is null.
    • memUTF16

      public static int memUTF16(CharSequence text, boolean nullTerminated, ByteBuffer target)
      Encodes and optionally null-terminates the specified text using UTF-16 encoding. The encoded text is stored in the specified ByteBuffer, at the current buffer position. The current buffer position is not modified by this operation. The target buffer is assumed to have enough remaining space to store the encoded text.
      Parameters:
      text - the text to encode
      nullTerminated - 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
      Throws:
      BufferOverflowException - if more than target.remaining() bytes are required to encode the text.
    • memUTF16

      public static int memUTF16(CharSequence text, boolean nullTerminated, ByteBuffer target, int offset)
      Encodes and optionally null-terminates the specified text using UTF-16 encoding. The encoded text is stored in the specified ByteBuffer at the specified position offset. The current buffer position is not modified by this operation. The target buffer is assumed to have enough remaining space to store the encoded text.
      Parameters:
      text - the text to encode
      nullTerminated - if true, the text will be terminated with a '\0'.
      target - the buffer in which to store the encoded text
      offset - the buffer position to which the string will be encoded
      Returns:
      the number of bytes of the encoded string
      Throws:
      BufferOverflowException - if more than target.capacity() - offset bytes are required to encode the text.
    • memLengthUTF16

      public static int memLengthUTF16(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 encode
      nullTerminated - if true, add the number of bytes required for null-termination
      Returns:
      the number of bytes
    • memLengthNT1

      public static int memLengthNT1(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(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 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 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 of maxLength bytes. 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
      maxLength - the maximum string length, in bytes
      Returns:
      the new ByteBuffer
    • memByteBufferNT1Safe

      public static @Nullable ByteBuffer memByteBufferNT1Safe(long address)
      Like memByteBufferNT1, but returns null if address is NULL.
    • memByteBufferNT1Safe

      public static @Nullable ByteBuffer memByteBufferNT1Safe(long address, int maxLength)
      Like memByteBufferNT1, but returns null if address is NULL.
    • memByteBufferNT2

      public static 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 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 of maxLength bytes. 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

      public static @Nullable ByteBuffer memByteBufferNT2Safe(long address)
      Like memByteBufferNT2, but returns null if address is NULL.
    • memByteBufferNT2Safe

      public static @Nullable ByteBuffer memByteBufferNT2Safe(long address, int maxLength)
      Like memByteBufferNT2, but returns null if address is NULL.
    • memASCII

      public static String memASCII(long address)
      Converts the null-terminated ASCII encoded string at the specified memory address to a String.
      Parameters:
      address - the string memory address
      Returns:
      the decoded String
    • memASCII

      public static String memASCII(long address, int length)
      Converts the ASCII encoded string at the specified memory address to a String.
      Parameters:
      address - the string memory address
      length - the number of bytes to decode
      Returns:
      the decoded String
    • memASCII

      public static String memASCII(ByteBuffer buffer)
      Decodes the bytes with index [position(), position()+remaining()) in buffer, as an ASCII string.

      The current position and limit of the specified buffer are not affected by this operation.

      Parameters:
      buffer - the ByteBuffer to decode
      Returns:
      the decoded String
    • memASCIISafe

      public static @Nullable String memASCIISafe(long address)
      Like memASCII, but returns null if address is NULL.
    • memASCIISafe

      public static @Nullable String memASCIISafe(long address, int length)
      Like memASCII, but returns null if address is NULL.
    • memASCIISafe

      public static @Nullable String memASCIISafe(@Nullable ByteBuffer buffer)
      Like memASCII, but returns null if buffer is null.
    • memASCII

      public static String memASCII(ByteBuffer buffer, int length)
      Decodes the bytes with index [position(), position()+length) in buffer, as an ASCII string.

      The current position and limit of the specified buffer are not affected by this operation.

      Parameters:
      buffer - the ByteBuffer to decode
      length - the number of bytes to decode
      Returns:
      the decoded String
    • memASCII

      public static String memASCII(ByteBuffer buffer, int length, int offset)
      Decodes the bytes with index [offset, offset+length) in buffer, as an ASCII string.

      The current position and limit of the specified buffer are not affected by this operation.

      Parameters:
      buffer - the ByteBuffer to decode
      length - the number of bytes to decode
      offset - the offset at which to start decoding.
      Returns:
      the decoded String
    • memUTF8

      public static String memUTF8(long address)
      Converts the null-terminated UTF-8 encoded string at the specified memory address to a String.
      Parameters:
      address - the string memory address
      Returns:
      the decoded String
    • memUTF8

      public static String memUTF8(long address, int length)
      Converts the UTF-8 encoded string at the specified memory address to a String.
      Parameters:
      address - the string memory address
      length - the number of bytes to decode
      Returns:
      the decoded String
    • memUTF8

      public static String memUTF8(ByteBuffer buffer)
      Decodes the bytes with index [position(), position()+remaining()) in buffer, as a UTF-8 string.

      The current position and limit of the specified buffer are not affected by this operation.

      Parameters:
      buffer - the ByteBuffer to decode
      Returns:
      the decoded String
    • memUTF8Safe

      public static @Nullable String memUTF8Safe(long address)
      Like memUTF8, but returns null if address is NULL.
    • memUTF8Safe

      public static @Nullable String memUTF8Safe(long address, int length)
      Like memUTF8, but returns null if address is NULL.
    • memUTF8Safe

      public static @Nullable String memUTF8Safe(@Nullable ByteBuffer buffer)
      Like memUTF8, but returns null if buffer is null.
    • memUTF8

      public static String memUTF8(ByteBuffer buffer, int length)
      Decodes the bytes with index [position(), position()+length) in buffer, as a UTF-8 string.

      The current position and limit of the specified buffer are not affected by this operation.

      Parameters:
      buffer - the ByteBuffer to decode
      length - the number of bytes to decode
      Returns:
      the decoded String
    • memUTF8

      public static String memUTF8(ByteBuffer buffer, int length, int offset)
      Decodes the bytes with index [offset, offset+length) in buffer, as a UTF-8 string.

      The current position and limit of the specified buffer are not affected by this operation.

      Parameters:
      buffer - the ByteBuffer to decode
      length - the number of bytes to decode
      offset - the offset at which to start decoding.
      Returns:
      the decoded String
    • memUTF16

      public static String memUTF16(long address)
      Converts the null-terminated UTF-16 encoded string at the specified memory address to a String.
      Parameters:
      address - the string memory address
      Returns:
      the decoded String
    • memUTF16

      public static String memUTF16(long address, int length)
      Converts the UTF-16 encoded string at the specified memory address to a String.
      Parameters:
      address - the string memory address
      length - the number of characters to decode
      Returns:
      the decoded String
    • memUTF16

      public static String memUTF16(ByteBuffer buffer)
      Decodes the bytes with index [position(), position()+remaining()) in buffer, as a UTF-16 string.

      The current position and limit of the specified buffer are not affected by this operation.

      Parameters:
      buffer - the ByteBuffer to decode
      Returns:
      the decoded String
    • memUTF16Safe

      public static @Nullable String memUTF16Safe(long address)
      Like memUTF16, but returns null if address is NULL.
    • memUTF16Safe

      public static @Nullable String memUTF16Safe(long address, int length)
      Like memUTF16, but returns null if address is NULL.
    • memUTF16Safe

      public static @Nullable String memUTF16Safe(@Nullable ByteBuffer buffer)
      Like memUTF16, but returns null if buffer is null.
    • memUTF16

      public static String memUTF16(ByteBuffer buffer, int length)
      Decodes the bytes with index [position(), position()+(length*2)) in buffer, as a UTF-16 string.

      The current position and limit of the specified buffer are not affected by this operation.

      Parameters:
      buffer - the ByteBuffer to decode
      length - the number of characters to decode
      Returns:
      the decoded String
    • memUTF16

      public static String memUTF16(ByteBuffer buffer, int length, int offset)
      Decodes the bytes with index [offset, offset+(length*2)) in buffer, as a UTF-16 string.

      The current position and limit of the specified buffer are not affected by this operation.

      Parameters:
      buffer - the ByteBuffer to decode
      length - the number of characters to decode
      offset - the offset at which to start decoding, in bytes.
      Returns:
      the decoded String