Class RPMallocConfig

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

    public class RPMallocConfig
    extends Struct
    implements NativeResource
    This struct enables configuration of a memory mapper providing map/unmap of memory pages. Defaults to VirtualAlloc/mmap if none provided. This allows rpmalloc to be used in contexts where memory is provided by internal means.

    Page size may be set explicitly in initialization. This allows the allocator to be used as a sub-allocator where the page granularity should be lower to reduce risk of wasting unused memory ranges.

    If rpmalloc is built with ENABLE_GUARDS, memory_overwrite may be set to detect writes before or after allocated memory blocks. This is not enabled in the default LWJGL build.

    Member documentation

    • memory_map – the memory map callback function
    • memory_unmap – the memory unmap callback function
    • page_size – the size of memory pages.

      The page size MUST be a power of two in [512,16384] range (29 to 214) unless 0 - set to 0 to use system page size. All memory mapping requests to memory_map will be made with size set to a multiple of the page size.

    • span_size – size of a span of memory blocks.

      MUST be a power of two, and in [4096,262144] range (unless 0 - set to 0 to use the default span size).

    • span_map_count – number of spans to map at each request to map new virtual memory blocks.

      This can be used to minimize the system call overhead at the cost of virtual memory address space. The extra mapped pages will not be written until actually used, so physical committed memory should not be affected in the default implementation.

      Will be aligned to a multiple of spans that match memory page size in case of huge pages.

    • enable_huge_pages – enable use of large/huge pages


     struct rpmalloc_config_t {
         void * (*memory_map) (size_t size, size_t *offset);
         void (*memory_unmap) (void *address, size_t size, size_t offset, int release);
         size_t page_size;
         size_t span_size;
         size_t span_map_count;
         int enable_huge_pages;
    • Field Detail

      • SIZEOF

        The struct size in bytes.
      • ALIGNOF

        The struct alignment in bytes.

        The struct member offsets.
    • Constructor Detail

      • RPMallocConfig

        public RPMallocConfig​(java.nio.ByteBuffer container)
        Creates a RPMallocConfig 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
      • memory_map

        public RPMemoryMapCallback memory_map()
        Returns the value of the memory_map field.
      • memory_unmap

        public RPMemoryUnmapCallback memory_unmap()
        Returns the value of the memory_unmap field.
      • page_size

        public long page_size()
        Returns the value of the page_size field.
      • span_size

        public long span_size()
        Returns the value of the span_size field.
      • span_map_count

        public long span_map_count()
        Returns the value of the span_map_count field.
      • enable_huge_pages

        public boolean enable_huge_pages()
        Returns the value of the enable_huge_pages field.
      • page_size

        public RPMallocConfig page_size​(long value)
        Sets the specified value to the page_size field.
      • span_size

        public RPMallocConfig span_size​(long value)
        Sets the specified value to the span_size field.
      • span_map_count

        public RPMallocConfig span_map_count​(long value)
        Sets the specified value to the span_map_count field.
      • enable_huge_pages

        public RPMallocConfig enable_huge_pages​(boolean value)
        Sets the specified value to the enable_huge_pages field.
      • set

        public RPMallocConfig set​(RPMallocConfig src)
        Copies the specified struct data to this struct.
        src - the source struct
        this struct
      • createSafe

        public static RPMallocConfig createSafe​(long address)
        Like create, but returns null if address is NULL.
      • npage_size

        public static long npage_size​(long struct)
        Unsafe version of page_size().
      • nspan_size

        public static long nspan_size​(long struct)
        Unsafe version of span_size().
      • nspan_map_count

        public static long nspan_map_count​(long struct)
        Unsafe version of span_map_count().
      • nenable_huge_pages

        public static int nenable_huge_pages​(long struct)
        Unsafe version of enable_huge_pages().
      • npage_size

        public static void npage_size​(long struct,
                                      long value)
        Unsafe version of page_size.
      • nspan_size

        public static void nspan_size​(long struct,
                                      long value)
        Unsafe version of span_size.
      • nspan_map_count

        public static void nspan_map_count​(long struct,
                                           long value)
        Unsafe version of span_map_count.
      • nenable_huge_pages

        public static void nenable_huge_pages​(long struct,
                                              int value)
        Unsafe version of enable_huge_pages.