Class RPMallocConfig
- java.lang.Object
-
- org.lwjgl.system.Pointer.Default
-
- org.lwjgl.system.Struct
-
- org.lwjgl.system.rpmalloc.RPMallocConfig
-
- All Implemented Interfaces:
java.lang.AutoCloseable,org.lwjgl.system.NativeResource,org.lwjgl.system.Pointer
public class RPMallocConfig extends org.lwjgl.system.Struct implements org.lwjgl.system.NativeResourceThis struct enables configuration of a memory mapper providing map/unmap of memory pages. Defaults toVirtualAlloc/mmapif 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_overwritemay be set to detect writes before or after allocated memory blocks. This is not enabled in the default LWJGL build.Layout
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); void (*error_callback) (char const *message); int (*map_fail_callback) (size_t size); size_tpage_size(); size_tspan_size(); size_tspan_map_count(); intenable_huge_pages(); char[4]; }
-
-
Field Summary
Fields Modifier and Type Field Description static intALIGNOFThe struct alignment in bytes.static intENABLE_HUGE_PAGES
ERROR_CALLBACK
MAP_FAIL_CALLBACK
MEMORY_MAP
MEMORY_UNMAP
PAGE_SIZEThe struct member offsets.static intSIZEOFThe struct size in bytes.static intSPAN_MAP_COUNT
SPAN_SIZEThe struct member offsets.
-
Constructor Summary
Constructors Constructor Description RPMallocConfig(java.nio.ByteBuffer container)Creates aRPMallocConfiginstance at the current position of the specifiedByteBuffercontainer.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static RPMallocConfigcalloc()Returns a newRPMallocConfiginstance allocated withmemCalloc.static RPMallocConfigcalloc(org.lwjgl.system.MemoryStack stack)Returns a newRPMallocConfiginstance allocated on the specifiedMemoryStackand initializes all its bits to zero.static RPMallocConfigcallocStack()Deprecated.static RPMallocConfigcallocStack(org.lwjgl.system.MemoryStack stack)Deprecated.static RPMallocConfigcreate()Returns a newRPMallocConfiginstance allocated withBufferUtils.static RPMallocConfigcreate(long address)Returns a newRPMallocConfiginstance for the specified memory address.static RPMallocConfigcreateSafe(long address)booleanenable_huge_pages()enable use of large/huge pages.RPMallocConfigenable_huge_pages(boolean value)Sets the specified value to theenable_huge_pages()field.RPErrorCallbackerror_callback()the error callback functionRPMallocConfigerror_callback(RPErrorCallbackI value)Sets the specified value to theerror_callback()field.static RPMallocConfigmalloc()Returns a newRPMallocConfiginstance allocated withmemAlloc.static RPMallocConfigmalloc(org.lwjgl.system.MemoryStack stack)Returns a newRPMallocConfiginstance allocated on the specifiedMemoryStack.static RPMallocConfigmallocStack()Deprecated.static RPMallocConfigmallocStack(org.lwjgl.system.MemoryStack stack)Deprecated.RPMapFailCallbackmap_fail_callback()the map fail callback functionRPMallocConfigmap_fail_callback(RPMapFailCallbackI value)Sets the specified value to themap_fail_callback()field.RPMemoryMapCallbackmemory_map()the memory map callback functionRPMallocConfigmemory_map(RPMemoryMapCallbackI value)Sets the specified value to thememory_map()field.RPMemoryUnmapCallbackmemory_unmap()the memory unmap callback functionRPMallocConfigmemory_unmap(RPMemoryUnmapCallbackI value)Sets the specified value to thememory_unmap()field.static intnenable_huge_pages(long struct)Unsafe version ofenable_huge_pages().static voidnenable_huge_pages(long struct, int value)Unsafe version ofenable_huge_pages.static RPErrorCallbacknerror_callback(long struct)Unsafe version oferror_callback().static voidnerror_callback(long struct, RPErrorCallbackI value)Unsafe version oferror_callback.static RPMapFailCallbacknmap_fail_callback(long struct)Unsafe version ofmap_fail_callback().static voidnmap_fail_callback(long struct, RPMapFailCallbackI value)Unsafe version ofmap_fail_callback.static RPMemoryMapCallbacknmemory_map(long struct)Unsafe version ofmemory_map().static voidnmemory_map(long struct, RPMemoryMapCallbackI value)Unsafe version ofmemory_map.static RPMemoryUnmapCallbacknmemory_unmap(long struct)Unsafe version ofmemory_unmap().static voidnmemory_unmap(long struct, RPMemoryUnmapCallbackI value)Unsafe version ofmemory_unmap.static longnpage_size(long struct)Unsafe version ofpage_size().static voidnpage_size(long struct, long value)Unsafe version ofpage_size.static longnspan_map_count(long struct)Unsafe version ofspan_map_count().static voidnspan_map_count(long struct, long value)Unsafe version ofspan_map_count.static longnspan_size(long struct)Unsafe version ofspan_size().static voidnspan_size(long struct, long value)Unsafe version ofspan_size.longpage_size()the size of memory pages.RPMallocConfigpage_size(long value)Sets the specified value to thepage_size()field.RPMallocConfigset(RPMallocConfig src)Copies the specified struct data to this struct.RPMallocConfigset(RPMemoryMapCallbackI memory_map, RPMemoryUnmapCallbackI memory_unmap, RPErrorCallbackI error_callback, RPMapFailCallbackI map_fail_callback, long page_size, long span_size, long span_map_count, boolean enable_huge_pages)Initializes this struct with the specified values.intsizeof()longspan_map_count()number of spans to map at each request to map new virtual memory blocks.RPMallocConfigspan_map_count(long value)Sets the specified value to thespan_map_count()field.longspan_size()size of a span of memory blocks.RPMallocConfigspan_size(long value)Sets the specified value to thespan_size()field.
-
-
-
Constructor Detail
-
RPMallocConfig
public RPMallocConfig(java.nio.ByteBuffer container)
Creates aRPMallocConfiginstance at the current position of the specifiedByteBuffercontainer. 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()
- Specified by:
sizeofin classorg.lwjgl.system.Struct
-
memory_map
@Nullable public RPMemoryMapCallback memory_map()
the memory map callback function
-
memory_unmap
@Nullable public RPMemoryUnmapCallback memory_unmap()
the memory unmap callback function
-
error_callback
@Nullable public RPErrorCallback error_callback()
the error callback function
-
map_fail_callback
@Nullable public RPMapFailCallback map_fail_callback()
the map fail callback function
-
page_size
public long 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 tomemory_mapwill be made with size set to a multiple of the page size.Used if
RPMALLOC_CONFIGURABLEis defined to 1, otherwise system page size is used.
-
span_size
public long 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).Used if
RPMALLOC_CONFIGURABLEis defined to 1.
-
span_map_count
public long 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
public boolean enable_huge_pages()
enable use of large/huge pages.If this flag is set to non-zero and page size is zero, the allocator will try to enable huge pages and auto detect the configuration. If this is set to non-zero and page_size is also non-zero, the allocator will assume huge pages have been configured and enabled prior to initializing the allocator.
For Windows, see large-page-support. For Linux, see hugetlbpage.txt.
-
memory_map
public RPMallocConfig memory_map(@Nullable RPMemoryMapCallbackI value)
Sets the specified value to thememory_map()field.
-
memory_unmap
public RPMallocConfig memory_unmap(@Nullable RPMemoryUnmapCallbackI value)
Sets the specified value to thememory_unmap()field.
-
error_callback
public RPMallocConfig error_callback(@Nullable RPErrorCallbackI value)
Sets the specified value to theerror_callback()field.
-
map_fail_callback
public RPMallocConfig map_fail_callback(@Nullable RPMapFailCallbackI value)
Sets the specified value to themap_fail_callback()field.
-
page_size
public RPMallocConfig page_size(long value)
Sets the specified value to thepage_size()field.
-
span_size
public RPMallocConfig span_size(long value)
Sets the specified value to thespan_size()field.
-
span_map_count
public RPMallocConfig span_map_count(long value)
Sets the specified value to thespan_map_count()field.
-
enable_huge_pages
public RPMallocConfig enable_huge_pages(boolean value)
Sets the specified value to theenable_huge_pages()field.
-
set
public RPMallocConfig set(RPMemoryMapCallbackI memory_map, RPMemoryUnmapCallbackI memory_unmap, RPErrorCallbackI error_callback, RPMapFailCallbackI map_fail_callback, long page_size, long span_size, long span_map_count, boolean enable_huge_pages)
Initializes this struct with the specified values.
-
set
public RPMallocConfig set(RPMallocConfig src)
Copies the specified struct data to this struct.- Parameters:
src- the source struct- Returns:
- this struct
-
malloc
public static RPMallocConfig malloc()
Returns a newRPMallocConfiginstance allocated withmemAlloc. The instance must be explicitly freed.
-
calloc
public static RPMallocConfig calloc()
Returns a newRPMallocConfiginstance allocated withmemCalloc. The instance must be explicitly freed.
-
create
public static RPMallocConfig create()
Returns a newRPMallocConfiginstance allocated withBufferUtils.
-
create
public static RPMallocConfig create(long address)
Returns a newRPMallocConfiginstance for the specified memory address.
-
createSafe
@Nullable public static RPMallocConfig createSafe(long address)
-
mallocStack
@Deprecated public static RPMallocConfig mallocStack()
Deprecated.Deprecated for removal in 3.4.0. Usemalloc(MemoryStack)instead.
-
callocStack
@Deprecated public static RPMallocConfig callocStack()
Deprecated.Deprecated for removal in 3.4.0. Usecalloc(MemoryStack)instead.
-
mallocStack
@Deprecated public static RPMallocConfig mallocStack(org.lwjgl.system.MemoryStack stack)
Deprecated.Deprecated for removal in 3.4.0. Usemalloc(MemoryStack)instead.
-
callocStack
@Deprecated public static RPMallocConfig callocStack(org.lwjgl.system.MemoryStack stack)
Deprecated.Deprecated for removal in 3.4.0. Usecalloc(MemoryStack)instead.
-
malloc
public static RPMallocConfig malloc(org.lwjgl.system.MemoryStack stack)
Returns a newRPMallocConfiginstance allocated on the specifiedMemoryStack.- Parameters:
stack- the stack from which to allocate
-
calloc
public static RPMallocConfig calloc(org.lwjgl.system.MemoryStack stack)
Returns a newRPMallocConfiginstance allocated on the specifiedMemoryStackand initializes all its bits to zero.- Parameters:
stack- the stack from which to allocate
-
nmemory_map
@Nullable public static RPMemoryMapCallback nmemory_map(long struct)
Unsafe version ofmemory_map().
-
nmemory_unmap
@Nullable public static RPMemoryUnmapCallback nmemory_unmap(long struct)
Unsafe version ofmemory_unmap().
-
nerror_callback
@Nullable public static RPErrorCallback nerror_callback(long struct)
Unsafe version oferror_callback().
-
nmap_fail_callback
@Nullable public static RPMapFailCallback nmap_fail_callback(long struct)
Unsafe version ofmap_fail_callback().
-
npage_size
public static long npage_size(long struct)
Unsafe version ofpage_size().
-
nspan_size
public static long nspan_size(long struct)
Unsafe version ofspan_size().
-
nspan_map_count
public static long nspan_map_count(long struct)
Unsafe version ofspan_map_count().
-
nenable_huge_pages
public static int nenable_huge_pages(long struct)
Unsafe version ofenable_huge_pages().
-
nmemory_map
public static void nmemory_map(long struct, @Nullable RPMemoryMapCallbackI value)Unsafe version ofmemory_map.
-
nmemory_unmap
public static void nmemory_unmap(long struct, @Nullable RPMemoryUnmapCallbackI value)Unsafe version ofmemory_unmap.
-
nerror_callback
public static void nerror_callback(long struct, @Nullable RPErrorCallbackI value)Unsafe version oferror_callback.
-
nmap_fail_callback
public static void nmap_fail_callback(long struct, @Nullable RPMapFailCallbackI value)Unsafe version ofmap_fail_callback.
-
npage_size
public static void npage_size(long struct, long value)Unsafe version ofpage_size.
-
nspan_size
public static void nspan_size(long struct, long value)Unsafe version ofspan_size.
-
nspan_map_count
public static void nspan_map_count(long struct, long value)Unsafe version ofspan_map_count.
-
nenable_huge_pages
public static void nenable_huge_pages(long struct, int value)Unsafe version ofenable_huge_pages.
-
-