Class NkAllocator

All Implemented Interfaces:
AutoCloseable, NativeResource, Pointer

public class NkAllocator extends Struct<NkAllocator> implements NativeResource

 struct nk_allocator {
     nk_handle userdata;
     nk_plugin_alloc alloc;
     nk_plugin_free mfree;
 }
  • Field Details

    • SIZEOF

      public static final int SIZEOF
      The struct size in bytes.
    • ALIGNOF

      public static final int ALIGNOF
      The struct alignment in bytes.
    • USERDATA

      public static final int USERDATA
      The struct member offsets.
    • ALLOC

      public static final int ALLOC
      The struct member offsets.
    • MFREE

      public static final int MFREE
      The struct member offsets.
  • Constructor Details

    • NkAllocator

      public NkAllocator(ByteBuffer container)
      Creates a NkAllocator instance at the current position of the specified ByteBuffer container. Changes to the buffer's content will be visible to the struct instance and vice versa.

      The created instance holds a strong reference to the container object.

  • Method Details

    • sizeof

      public int sizeof()
      Description copied from class: Struct
      Returns sizeof(struct).
      Specified by:
      sizeof in class Struct<NkAllocator>
    • userdata

      public NkHandle userdata()
      Returns:
      a NkHandle view of the userdata field.
    • alloc

      public @Nullable NkPluginAlloc alloc()
      Returns:
      the value of the alloc field.
    • mfree

      public @Nullable NkPluginFree mfree()
      Returns:
      the value of the mfree field.
    • userdata

      public NkAllocator userdata(NkHandle value)
      Copies the specified NkHandle to the userdata field.
    • userdata

      public NkAllocator userdata(Consumer<NkHandle> consumer)
      Passes the userdata field to the specified Consumer.
    • alloc

      public NkAllocator alloc(@Nullable NkPluginAllocI value)
      Sets the specified value to the alloc field.
    • mfree

      public NkAllocator mfree(@Nullable NkPluginFreeI value)
      Sets the specified value to the mfree field.
    • set

      public NkAllocator set(NkHandle userdata, NkPluginAllocI alloc, NkPluginFreeI mfree)
      Initializes this struct with the specified values.
    • set

      public NkAllocator set(NkAllocator src)
      Copies the specified struct data to this struct.
      Parameters:
      src - the source struct
      Returns:
      this struct
    • malloc

      public static NkAllocator malloc()
      Returns a new NkAllocator instance allocated with memAlloc. The instance must be explicitly freed.
    • calloc

      public static NkAllocator calloc()
      Returns a new NkAllocator instance allocated with memCalloc. The instance must be explicitly freed.
    • create

      public static NkAllocator create()
      Returns a new NkAllocator instance allocated with BufferUtils.
    • create

      public static NkAllocator create(long address)
      Returns a new NkAllocator instance for the specified memory address.
    • createSafe

      public static @Nullable NkAllocator createSafe(long address)
      Like create, but returns null if address is NULL.
    • malloc

      public static NkAllocator.Buffer malloc(int capacity)
      Returns a new NkAllocator.Buffer instance allocated with memAlloc. The instance must be explicitly freed.
      Parameters:
      capacity - the buffer capacity
    • calloc

      public static NkAllocator.Buffer calloc(int capacity)
      Returns a new NkAllocator.Buffer instance allocated with memCalloc. The instance must be explicitly freed.
      Parameters:
      capacity - the buffer capacity
    • create

      public static NkAllocator.Buffer create(int capacity)
      Returns a new NkAllocator.Buffer instance allocated with BufferUtils.
      Parameters:
      capacity - the buffer capacity
    • create

      public static NkAllocator.Buffer create(long address, int capacity)
      Create a NkAllocator.Buffer instance at the specified memory.
      Parameters:
      address - the memory address
      capacity - the buffer capacity
    • createSafe

      public static @Nullable NkAllocator.Buffer createSafe(long address, int capacity)
      Like create, but returns null if address is NULL.
    • malloc

      public static NkAllocator malloc(MemoryStack stack)
      Returns a new NkAllocator instance allocated on the specified MemoryStack.
      Parameters:
      stack - the stack from which to allocate
    • calloc

      public static NkAllocator calloc(MemoryStack stack)
      Returns a new NkAllocator instance allocated on the specified MemoryStack and initializes all its bits to zero.
      Parameters:
      stack - the stack from which to allocate
    • malloc

      public static NkAllocator.Buffer malloc(int capacity, MemoryStack stack)
      Returns a new NkAllocator.Buffer instance allocated on the specified MemoryStack.
      Parameters:
      capacity - the buffer capacity
      stack - the stack from which to allocate
    • calloc

      public static NkAllocator.Buffer calloc(int capacity, MemoryStack stack)
      Returns a new NkAllocator.Buffer instance allocated on the specified MemoryStack and initializes all its bits to zero.
      Parameters:
      capacity - the buffer capacity
      stack - the stack from which to allocate
    • nuserdata

      public static NkHandle nuserdata(long struct)
      Unsafe version of userdata().
    • nalloc

      public static @Nullable NkPluginAlloc nalloc(long struct)
      Unsafe version of alloc().
    • nmfree

      public static @Nullable NkPluginFree nmfree(long struct)
      Unsafe version of mfree().
    • nuserdata

      public static void nuserdata(long struct, NkHandle value)
      Unsafe version of userdata.
    • nalloc

      public static void nalloc(long struct, @Nullable NkPluginAllocI value)
      Unsafe version of alloc.
    • nmfree

      public static void nmfree(long struct, @Nullable NkPluginFreeI value)
      Unsafe version of mfree.