Class NkBuffer

  • All Implemented Interfaces:
    java.lang.AutoCloseable, NativeResource, Pointer

    public class NkBuffer
    extends Struct
    implements NativeResource

    Member documentation

    • marker – buffer marker to free a buffer to a certain offset
    • pool – allocator callback for dynamic buffers
    • type – memory management type
    • memory – memory and size of the current memory block
    • grow_factor – growing factor for dynamic memory management
    • allocated – total amount of memory allocated
    • needed – totally consumed memory given that enough memory is present
    • calls – number of allocation calls
    • size – current size of the buffer

    Layout

    
     struct nk_buffer {
         struct nk_buffer_marker marker[2];
         struct nk_allocator pool;
         enum nk_allocation_type type;
         struct nk_memory memory;
         float grow_factor;
         nk_size allocated;
         nk_size needed;
         nk_size calls;
         nk_size size;
     }
    • Field Detail

      • SIZEOF

        The struct size in bytes.
      • ALIGNOF

        The struct alignment in bytes.
      • MARKER, POOL, TYPE, MEMORY, GROW_FACTOR, ALLOCATED, NEEDED, CALLS, SIZE

        The struct member offsets.
    • Constructor Detail

      • NkBuffer

        public NkBuffer​(java.nio.ByteBuffer container)
        Creates a NkBuffer 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 Detail

      • sizeof

        public int sizeof()
        Description copied from class: Struct
        Returns sizeof(struct).
        Specified by:
        sizeof in class Struct
      • marker

        public NkBufferMarker marker​(int index)
        Returns a NkBufferMarker view of the struct at the specified index of the marker field.
      • pool

        public NkBuffer pool​(java.util.function.Consumer<NkAllocator> consumer)
        Passes the pool field to the specified Consumer.
      • type

        public int type()
        Returns the value of the type field.
      • memory

        public NkMemory memory()
        Returns a NkMemory view of the memory field.
      • grow_factor

        public float grow_factor()
        Returns the value of the grow_factor field.
      • allocated

        public long allocated()
        Returns the value of the allocated field.
      • needed

        public long needed()
        Returns the value of the needed field.
      • calls

        public long calls()
        Returns the value of the calls field.
      • size

        public long size()
        Returns the value of the size field.
      • malloc

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

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

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

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

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

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

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

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

        public static NkBuffer callocStack()
        Returns a new NkBuffer instance allocated on the thread-local MemoryStack and initializes all its bits to zero.
      • mallocStack

        public static NkBuffer mallocStack​(MemoryStack stack)
        Returns a new NkBuffer instance allocated on the specified MemoryStack.
        Parameters:
        stack - the stack from which to allocate
      • callocStack

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

        public static NkBuffer.Buffer callocStack​(int capacity)
        Returns a new NkBuffer.Buffer instance allocated on the thread-local MemoryStack and initializes all its bits to zero.
        Parameters:
        capacity - the buffer capacity
      • callocStack

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

        public static NkBufferMarker nmarker​(long struct,
                                             int index)
        Unsafe version of marker.
      • ntype

        public static int ntype​(long struct)
        Unsafe version of type().
      • nmemory

        public static NkMemory nmemory​(long struct)
        Unsafe version of memory().
      • ngrow_factor

        public static float ngrow_factor​(long struct)
        Unsafe version of grow_factor().
      • nallocated

        public static long nallocated​(long struct)
        Unsafe version of allocated().
      • nneeded

        public static long nneeded​(long struct)
        Unsafe version of needed().
      • ncalls

        public static long ncalls​(long struct)
        Unsafe version of calls().
      • nsize

        public static long nsize​(long struct)
        Unsafe version of size().