Class RPMallocConfig
- All Implemented Interfaces:
AutoCloseable
,NativeResource
,Pointer
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.
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_t page_size()
;
size_t span_size()
;
size_t span_map_count()
;
int enable_huge_pages()
;
char const * page_name()
;
char const * huge_page_name()
;
}
-
Nested Class Summary
Nested classes/interfaces inherited from class org.lwjgl.system.Struct
Struct.StructValidation
Nested classes/interfaces inherited from interface org.lwjgl.system.Pointer
Pointer.Default
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
The struct alignment in bytes.static final int
The struct member offsets.static final int
The struct member offsets.static final int
The struct member offsets.static final int
The struct member offsets.static final int
The struct member offsets.static final int
The struct member offsets.static final int
The struct member offsets.static final int
The struct member offsets.static final int
The struct size in bytes.static final int
The struct member offsets.static final int
The struct member offsets.Fields inherited from interface org.lwjgl.system.Pointer
BITS32, BITS64, CLONG_SHIFT, CLONG_SIZE, POINTER_SHIFT, POINTER_SIZE
-
Constructor Summary
ConstructorDescriptionRPMallocConfig
(ByteBuffer container) Creates aRPMallocConfig
instance at the current position of the specifiedByteBuffer
container. -
Method Summary
Modifier and TypeMethodDescriptionstatic RPMallocConfig
calloc()
Returns a newRPMallocConfig
instance allocated withmemCalloc
.static RPMallocConfig
calloc
(MemoryStack stack) Returns a newRPMallocConfig
instance allocated on the specifiedMemoryStack
and initializes all its bits to zero.static RPMallocConfig
Deprecated.static RPMallocConfig
callocStack
(MemoryStack stack) Deprecated.static RPMallocConfig
create()
Returns a newRPMallocConfig
instance allocated withBufferUtils
.static RPMallocConfig
create
(long address) Returns a newRPMallocConfig
instance for the specified memory address.static RPMallocConfig
createSafe
(long address) boolean
enable use of large/huge pages.enable_huge_pages
(boolean value) Sets the specified value to theenable_huge_pages()
field.the error callback functionerror_callback
(RPErrorCallbackI value) Sets the specified value to theerror_callback()
field.huge allocated pages name for systems supporting it to be able to distinguish among anonymous regionshuge_page_name
(ByteBuffer value) Sets the address of the specified encoded string to thehuge_page_name()
field.huge allocated pages name for systems supporting it to be able to distinguish among anonymous regionsstatic RPMallocConfig
malloc()
Returns a newRPMallocConfig
instance allocated withmemAlloc
.static RPMallocConfig
malloc
(MemoryStack stack) Returns a newRPMallocConfig
instance allocated on the specifiedMemoryStack
.static RPMallocConfig
Deprecated.static RPMallocConfig
mallocStack
(MemoryStack stack) Deprecated.the map fail callback functionSets the specified value to themap_fail_callback()
field.the memory map callback functionmemory_map
(RPMemoryMapCallbackI value) Sets the specified value to thememory_map()
field.the memory unmap callback functionSets the specified value to thememory_unmap()
field.static int
nenable_huge_pages
(long struct) Unsafe version ofenable_huge_pages()
.static void
nenable_huge_pages
(long struct, int value) Unsafe version ofenable_huge_pages
.static RPErrorCallback
nerror_callback
(long struct) Unsafe version oferror_callback()
.static void
nerror_callback
(long struct, RPErrorCallbackI value) Unsafe version oferror_callback
.static ByteBuffer
nhuge_page_name
(long struct) Unsafe version ofhuge_page_name()
.static void
nhuge_page_name
(long struct, ByteBuffer value) Unsafe version ofhuge_page_name
.static String
nhuge_page_nameString
(long struct) Unsafe version ofhuge_page_nameString()
.static RPMapFailCallback
nmap_fail_callback
(long struct) Unsafe version ofmap_fail_callback()
.static void
nmap_fail_callback
(long struct, RPMapFailCallbackI value) Unsafe version ofmap_fail_callback
.static RPMemoryMapCallback
nmemory_map
(long struct) Unsafe version ofmemory_map()
.static void
nmemory_map
(long struct, RPMemoryMapCallbackI value) Unsafe version ofmemory_map
.static RPMemoryUnmapCallback
nmemory_unmap
(long struct) Unsafe version ofmemory_unmap()
.static void
nmemory_unmap
(long struct, RPMemoryUnmapCallbackI value) Unsafe version ofmemory_unmap
.static ByteBuffer
npage_name
(long struct) Unsafe version ofpage_name()
.static void
npage_name
(long struct, ByteBuffer value) Unsafe version ofpage_name
.static String
npage_nameString
(long struct) Unsafe version ofpage_nameString()
.static long
npage_size
(long struct) Unsafe version ofpage_size()
.static void
npage_size
(long struct, long value) Unsafe version ofpage_size
.static long
nspan_map_count
(long struct) Unsafe version ofspan_map_count()
.static void
nspan_map_count
(long struct, long value) Unsafe version ofspan_map_count
.static long
nspan_size
(long struct) Unsafe version ofspan_size()
.static void
nspan_size
(long struct, long value) Unsafe version ofspan_size
.allocated pages name for systems supporting it to be able to distinguish among anonymous regionspage_name
(ByteBuffer value) Sets the address of the specified encoded string to thepage_name()
field.allocated pages name for systems supporting it to be able to distinguish among anonymous regionslong
the size of memory pages.page_size
(long value) Sets the specified value to thepage_size()
field.set
(RPMallocConfig src) Copies the specified struct data to this struct.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, ByteBuffer page_name, ByteBuffer huge_page_name) Initializes this struct with the specified values.int
sizeof()
Returnssizeof(struct)
.long
number of spans to map at each request to map new virtual memory blocks.span_map_count
(long value) Sets the specified value to thespan_map_count()
field.long
size of a span of memory blocks.span_size
(long value) Sets the specified value to thespan_size()
field.Methods inherited from class org.lwjgl.system.Pointer.Default
address, equals, hashCode, toString
Methods inherited from interface org.lwjgl.system.NativeResource
close, free
-
Field Details
-
SIZEOF
public static final int SIZEOFThe struct size in bytes. -
ALIGNOF
public static final int ALIGNOFThe struct alignment in bytes. -
MEMORY_MAP
public static final int MEMORY_MAPThe struct member offsets. -
MEMORY_UNMAP
public static final int MEMORY_UNMAPThe struct member offsets. -
ERROR_CALLBACK
public static final int ERROR_CALLBACKThe struct member offsets. -
MAP_FAIL_CALLBACK
public static final int MAP_FAIL_CALLBACKThe struct member offsets. -
PAGE_SIZE
public static final int PAGE_SIZEThe struct member offsets. -
SPAN_SIZE
public static final int SPAN_SIZEThe struct member offsets. -
SPAN_MAP_COUNT
public static final int SPAN_MAP_COUNTThe struct member offsets. -
ENABLE_HUGE_PAGES
public static final int ENABLE_HUGE_PAGESThe struct member offsets. -
PAGE_NAME
public static final int PAGE_NAMEThe struct member offsets. -
HUGE_PAGE_NAME
public static final int HUGE_PAGE_NAMEThe struct member offsets.
-
-
Constructor Details
-
RPMallocConfig
Creates aRPMallocConfig
instance at the current position of the specifiedByteBuffer
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
Returnssizeof(struct)
.- Specified by:
sizeof
in classStruct<RPMallocConfig>
-
memory_map
the memory map callback function -
memory_unmap
the memory unmap callback function -
error_callback
the error callback function -
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_map
will be made with size set to a multiple of the page size.Used if
RPMALLOC_CONFIGURABLE
is 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_CONFIGURABLE
is 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.
-
page_name
allocated pages name for systems supporting it to be able to distinguish among anonymous regions -
page_nameString
allocated pages name for systems supporting it to be able to distinguish among anonymous regions -
huge_page_name
huge allocated pages name for systems supporting it to be able to distinguish among anonymous regions -
huge_page_nameString
huge allocated pages name for systems supporting it to be able to distinguish among anonymous regions -
memory_map
Sets the specified value to thememory_map()
field. -
memory_unmap
Sets the specified value to thememory_unmap()
field. -
error_callback
Sets the specified value to theerror_callback()
field. -
map_fail_callback
Sets the specified value to themap_fail_callback()
field. -
page_size
Sets the specified value to thepage_size()
field. -
span_size
Sets the specified value to thespan_size()
field. -
span_map_count
Sets the specified value to thespan_map_count()
field. -
enable_huge_pages
Sets the specified value to theenable_huge_pages()
field. -
page_name
Sets the address of the specified encoded string to thepage_name()
field. -
huge_page_name
Sets the address of the specified encoded string to thehuge_page_name()
field. -
set
public RPMallocConfig set(@Nullable RPMemoryMapCallbackI memory_map, @Nullable RPMemoryUnmapCallbackI memory_unmap, @Nullable RPErrorCallbackI error_callback, @Nullable RPMapFailCallbackI map_fail_callback, long page_size, long span_size, long span_map_count, boolean enable_huge_pages, @Nullable ByteBuffer page_name, @Nullable ByteBuffer huge_page_name) Initializes this struct with the specified values. -
set
Copies the specified struct data to this struct.- Parameters:
src
- the source struct- Returns:
- this struct
-
malloc
Returns a newRPMallocConfig
instance allocated withmemAlloc
. The instance must be explicitly freed. -
calloc
Returns a newRPMallocConfig
instance allocated withmemCalloc
. The instance must be explicitly freed. -
create
Returns a newRPMallocConfig
instance allocated withBufferUtils
. -
create
Returns a newRPMallocConfig
instance for the specified memory address. -
createSafe
-
mallocStack
Deprecated.Deprecated for removal in 3.4.0. Usemalloc(MemoryStack)
instead. -
callocStack
Deprecated.Deprecated for removal in 3.4.0. Usecalloc(MemoryStack)
instead. -
mallocStack
Deprecated.Deprecated for removal in 3.4.0. Usemalloc(MemoryStack)
instead. -
callocStack
Deprecated.Deprecated for removal in 3.4.0. Usecalloc(MemoryStack)
instead. -
malloc
Returns a newRPMallocConfig
instance allocated on the specifiedMemoryStack
.- Parameters:
stack
- the stack from which to allocate
-
calloc
Returns a newRPMallocConfig
instance allocated on the specifiedMemoryStack
and initializes all its bits to zero.- Parameters:
stack
- the stack from which to allocate
-
nmemory_map
Unsafe version ofmemory_map()
. -
nmemory_unmap
Unsafe version ofmemory_unmap()
. -
nerror_callback
Unsafe version oferror_callback()
. -
nmap_fail_callback
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()
. -
npage_name
Unsafe version ofpage_name()
. -
npage_nameString
Unsafe version ofpage_nameString()
. -
nhuge_page_name
Unsafe version ofhuge_page_name()
. -
nhuge_page_nameString
Unsafe version ofhuge_page_nameString()
. -
nmemory_map
Unsafe version ofmemory_map
. -
nmemory_unmap
Unsafe version ofmemory_unmap
. -
nerror_callback
Unsafe version oferror_callback
. -
nmap_fail_callback
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
. -
npage_name
Unsafe version ofpage_name
. -
nhuge_page_name
Unsafe version ofhuge_page_name
.
-