You are required to call these functions from your own code in order to initialize and finalize the allocator in your process and threads:
malloc_initialize: Call at process start to initialize the allocatormalloc_finalize: Call at process exit to finalize the allocatormalloc_thread_initialize: Call at each thread start to initialize the thread local data for the allocatormalloc_thread_finalize: Call at each thread exit to finalize and release thread cache back to global cacheThen simply use the malloc/free and the other malloc style replacement functions. Remember all allocations are 16-byte aligned, so no need to
call the explicit memalign/aligned_alloc/posix_memalign functions unless you need greater alignment, they are simply wrappers to make it
easier to replace in existing code.
The rpmalloc build in LWJGL is configured with RPMALLOC_CONFIGURABLE=1 and ENABLE_STATISTICS=0.
| Modifier and Type | Field and Description |
|---|---|
| public static final int | RPMALLOC_GROW_OR_FAIL
Flag to |
| public static final int | RPMALLOC_NO_PRESERVE
Flag to |
| Access | Constructor and Description |
|---|---|
| protected |
| Modifier and Type | Method and Description |
|---|---|
| public static native long | |
| public static native long | |
| public static native long | nrpaligned_realloc(long ptr, long alignment, long size, long oldsize, int flags)
Unsafe version of: |
| public static native long | |
| public static native void | |
| public static native long | |
| public static native long | |
| public static native long | |
| public static native void | |
| public static native long | nrpmalloc_heap_aligned_alloc(long heap, long alignment, long size)
Unsafe version of: |
| public static native long | nrpmalloc_heap_aligned_calloc(long heap, long alignment, long num, long size)
Unsafe version of: |
| public static native long | nrpmalloc_heap_aligned_realloc(long heap, long ptr, long alignment, long size, int flags)
Unsafe version of: |
| public static native long | |
| public static native long | |
| public static native void | |
| public static native void | |
| public static native long | nrpmalloc_heap_realloc(long heap, long ptr, long size, int flags)
Unsafe version of: |
| public static native int | |
| public static native int | |
| public static native int | |
| public static native void | |
| public static native void | |
| public static native long | |
| public static native long | |
| public static native int | |
| public static native long | |
| public static ByteBuffer | rpaligned_alloc(long alignment, long size)
Allocates a memory block of at least the given size and alignment. |
| pack-priv static native long | |
| public static ByteBuffer | rpaligned_calloc(long alignment, long num, long size)
Allocates a memory block of at least the given size and alignment, and zero initializes it. |
| public static ByteBuffer | rpaligned_realloc(ByteBuffer ptr, long alignment, long size, int flags)
Reallocates the given block to at least the given size and alignment, with optional control flags (see |
| public static ByteBuffer | rpcalloc(long num, long size)
Allocates a memory block of at least the given size and zero initializes it. |
| pack-priv static native long | |
| public static void | |
| public static void | |
| public static void | |
| public static void | |
| public static void | |
| public static void | |
| public static void | |
| pack-priv static native long | |
| public static ByteBuffer | |
| pack-priv static native long | |
| public static RPMallocConfig | |
| public static native void | |
| public static long | |
| public static long | |
| public static long | |
| public static long | |
| public static long | |
| public static long | |
| public static long | |
| public static void | |
| public static native long | |
| public static ByteBuffer | rpmalloc_heap_aligned_alloc(long heap, long alignment, long size)
Allocates a memory block of at least the given size using the given heap. |
| public static ByteBuffer | rpmalloc_heap_aligned_calloc(long heap, long alignment, long
' num, long size)Allocates a memory block of at least the given size using the given heap and zero initializes it. |
| public static ByteBuffer | rpmalloc_heap_aligned_realloc(long heap, ByteBuffer ptr, long alignment, long size, int flags)
Reallocates the given block to at least the given size. |
| public static ByteBuffer | rpmalloc_heap_alloc(long heap, long size)
Allocates a memory block of at least the given size using the given heap. |
| public static ByteBuffer | rpmalloc_heap_calloc(long heap, long num, long size)
Allocates a memory block of at least the given size using the given heap and zero initializes it. |
| public static void | |
| public static void | |
| public static void | |
| public static void | |
| public static void | |
| public static void | |
| public static void | |
| public static void | |
| public static ByteBuffer | rpmalloc_heap_realloc(long heap, ByteBuffer ptr, long size, int flags)
Reallocates the given block to at least the given size. |
| public static native void | rpmalloc_heap_release(long heap)
Releases a heap (does NOT free the memory allocated by the heap, use |
| public static native void | rpmalloc_heap_thread_set_current(long heap)
Sets the given heap as the current heap for the calling thread. |
| public static boolean | |
| public static boolean | rpmalloc_initialize_config(RPMallocConfig
an optional config)RPMallocConfig instanceInitializes allocator with given configuration. |
| public static boolean | |
| public static native void | |
| public static void | rpmalloc_thread_finalize(boolean
pass non-zero to release thread caches to global cache release_caches)Finalizes allocator for calling thread. |
| public static native void | |
| public static void | |
| public static long | rpmalloc_usable_size(ByteBuffer ptr)
Queries the usable size of the given memory block (from given pointer to the end of block). |
| public static long | rpmalloc_usable_size(ShortBuffer ptr)
Queries the usable size of the given memory block (from given pointer to the end of block). |
| public static long | rpmalloc_usable_size(IntBuffer ptr)
Queries the usable size of the given memory block (from given pointer to the end of block). |
| public static long | rpmalloc_usable_size(LongBuffer ptr)
Queries the usable size of the given memory block (from given pointer to the end of block). |
| public static long | rpmalloc_usable_size(FloatBuffer ptr)
Queries the usable size of the given memory block (from given pointer to the end of block). |
| public static long | rpmalloc_usable_size(DoubleBuffer ptr)
Queries the usable size of the given memory block (from given pointer to the end of block). |
| public static long | rpmalloc_usable_size(PointerBuffer ptr)
Queries the usable size of the given memory block (from given pointer to the end of block). |
| public static ByteBuffer | rpmemalign(long alignment, long size)
Allocates a memory block of at least the given size and alignment. |
| public static int | rpposix_memalign(PointerBuffer memptr, long alignment, long size)
Allocates a memory block of at least the given size and alignment. |
| public static ByteBuffer | |
| pack-priv static native long |
| RPMALLOC_GROW_OR_FAIL | back to summary |
|---|---|
| public static final int RPMALLOC_GROW_OR_FAIL Flag to | |
| RPMALLOC_NO_PRESERVE | back to summary |
|---|---|
| public static final int RPMALLOC_NO_PRESERVE Flag to | |
| RPmalloc | back to summary |
|---|---|
| protected RPmalloc() | |
| nrpaligned_alloc | back to summary |
|---|---|
| public static native long nrpaligned_alloc(long alignment, long size) Unsafe version of: | |
| nrpaligned_calloc | back to summary |
|---|---|
| public static native long nrpaligned_calloc(long alignment, long num, long size) Unsafe version of: | |
| nrpaligned_realloc | back to summary |
|---|---|
| public static native long nrpaligned_realloc(long ptr, long alignment, long size, long oldsize, int flags) Unsafe version of: | |
| nrpcalloc | back to summary |
|---|---|
| public static native long nrpcalloc(long num, long size) Unsafe version of: | |
| nrpfree | back to summary |
|---|---|
| public static native void nrpfree(long ptr) Unsafe version of: | |
| nrpmalloc | back to summary |
|---|---|
| public static native long nrpmalloc(long size) Unsafe version of: | |
| nrpmalloc_config | back to summary |
|---|---|
| public static native long nrpmalloc_config() Unsafe version of: | |
| nrpmalloc_get_heap_for_ptr | back to summary |
|---|---|
| public static native long nrpmalloc_get_heap_for_ptr(long ptr) Unsafe version of: | |
| nrpmalloc_global_statistics | back to summary |
|---|---|
| public static native void nrpmalloc_global_statistics(long stats) Unsafe version of: | |
| nrpmalloc_heap_aligned_alloc | back to summary |
|---|---|
| public static native long nrpmalloc_heap_aligned_alloc(long heap, long alignment, long size) Unsafe version of: | |
| nrpmalloc_heap_aligned_calloc | back to summary |
|---|---|
| public static native long nrpmalloc_heap_aligned_calloc(long heap, long alignment, long num, long size) Unsafe version of: | |
| nrpmalloc_heap_aligned_realloc | back to summary |
|---|---|
| public static native long nrpmalloc_heap_aligned_realloc(long heap, long ptr, long alignment, long size, int flags) Unsafe version of: | |
| nrpmalloc_heap_alloc | back to summary |
|---|---|
| public static native long nrpmalloc_heap_alloc(long heap, long size) Unsafe version of: | |
| nrpmalloc_heap_calloc | back to summary |
|---|---|
| public static native long nrpmalloc_heap_calloc(long heap, long num, long size) Unsafe version of: | |
| nrpmalloc_heap_free | back to summary |
|---|---|
| public static native void nrpmalloc_heap_free(long heap, long ptr) Unsafe version of: | |
| nrpmalloc_heap_free_all | back to summary |
|---|---|
| public static native void nrpmalloc_heap_free_all(long heap) Unsafe version of: | |
| nrpmalloc_heap_realloc | back to summary |
|---|---|
| public static native long nrpmalloc_heap_realloc(long heap, long ptr, long size, int flags) Unsafe version of: | |
| nrpmalloc_initialize | back to summary |
|---|---|
| public static native int nrpmalloc_initialize() Unsafe version of: | |
| nrpmalloc_initialize_config | back to summary |
|---|---|
| public static native int nrpmalloc_initialize_config(long config) Unsafe version of: | |
| nrpmalloc_is_thread_initialized | back to summary |
|---|---|
| public static native int nrpmalloc_is_thread_initialized() Unsafe version of: | |
| nrpmalloc_thread_finalize | back to summary |
|---|---|
| public static native void nrpmalloc_thread_finalize(int release_caches) Unsafe version of: | |
| nrpmalloc_thread_statistics | back to summary |
|---|---|
| public static native void nrpmalloc_thread_statistics(long stats) Unsafe version of: | |
| nrpmalloc_usable_size | back to summary |
|---|---|
| public static native long nrpmalloc_usable_size(long ptr) Unsafe version of: | |
| nrpmemalign | back to summary |
|---|---|
| public static native long nrpmemalign(long alignment, long size) Unsafe version of: | |
| nrpposix_memalign | back to summary |
|---|---|
| public static native int nrpposix_memalign(long memptr, long alignment, long size) Unsafe version of: | |
| nrprealloc | back to summary |
|---|---|
| public static native long nrprealloc(long ptr, long size) Unsafe version of: | |
| rpaligned_alloc | back to summary |
|---|---|
| public static ByteBuffer rpaligned_alloc(long alignment, long size) Allocates a memory block of at least the given size and alignment. Alignment must be a power of two and a multiple of
| |
| rpaligned_alloc_address | back to summary |
|---|---|
| pack-priv static native long rpaligned_alloc_address() The
| |
| rpaligned_calloc | back to summary |
|---|---|
| public static ByteBuffer rpaligned_calloc(long alignment, long num, long size) Allocates a memory block of at least the given size and alignment, and zero initializes it. Alignment must be a power of two and a multiple of
| |
| rpaligned_realloc | back to summary |
|---|---|
| public static ByteBuffer rpaligned_realloc(ByteBuffer ptr, long alignment, long size, int flags) Reallocates the given block to at least the given size and alignment, with optional control flags (see Alignment must be a power of two and a multiple of
| |
| rpcalloc | back to summary |
|---|---|
| public static ByteBuffer rpcalloc(long num, long size) Allocates a memory block of at least the given size and zero initializes it.
| |
| rpcalloc_address | back to summary |
|---|---|
| pack-priv static native long rpcalloc_address() The
| |
| rpfree | back to summary |
|---|---|
| public static void rpfree(ByteBuffer ptr) Frees the given memory block. | |
| rpfree | back to summary |
|---|---|
| public static void rpfree(ShortBuffer ptr) Frees the given memory block. | |
| rpfree | back to summary |
|---|---|
| public static void rpfree(IntBuffer ptr) Frees the given memory block. | |
| rpfree | back to summary |
|---|---|
| public static void rpfree(LongBuffer ptr) Frees the given memory block. | |
| rpfree | back to summary |
|---|---|
| public static void rpfree(FloatBuffer ptr) Frees the given memory block. | |
| rpfree | back to summary |
|---|---|
| public static void rpfree(DoubleBuffer ptr) Frees the given memory block. | |
| rpfree | back to summary |
|---|---|
| public static void rpfree(PointerBuffer ptr) Frees the given memory block. | |
| rpfree_address | back to summary |
|---|---|
| pack-priv static native long rpfree_address() The
| |
| rpmalloc | back to summary |
|---|---|
| public static ByteBuffer rpmalloc(long size) Allocates a memory block of at least the given size.
| |
| rpmalloc_address | back to summary |
|---|---|
| pack-priv static native long rpmalloc_address() The
| |
| rpmalloc_config | back to summary |
|---|---|
| public static RPMallocConfig rpmalloc_config() Gets allocator configuration.
| |
| rpmalloc_finalize | back to summary |
|---|---|
| public static native void rpmalloc_finalize() Finalizes allocator. | |
| rpmalloc_get_heap_for_ptr | back to summary |
|---|---|
| public static long rpmalloc_get_heap_for_ptr(ByteBuffer ptr) Returns which heap the given pointer is allocated on.
| |
| rpmalloc_get_heap_for_ptr | back to summary |
|---|---|
| public static long rpmalloc_get_heap_for_ptr(ShortBuffer ptr) Returns which heap the given pointer is allocated on.
| |
| rpmalloc_get_heap_for_ptr | back to summary |
|---|---|
| public static long rpmalloc_get_heap_for_ptr(IntBuffer ptr) Returns which heap the given pointer is allocated on.
| |
| rpmalloc_get_heap_for_ptr | back to summary |
|---|---|
| public static long rpmalloc_get_heap_for_ptr(LongBuffer ptr) Returns which heap the given pointer is allocated on.
| |
| rpmalloc_get_heap_for_ptr | back to summary |
|---|---|
| public static long rpmalloc_get_heap_for_ptr(FloatBuffer ptr) Returns which heap the given pointer is allocated on.
| |
| rpmalloc_get_heap_for_ptr | back to summary |
|---|---|
| public static long rpmalloc_get_heap_for_ptr(DoubleBuffer ptr) Returns which heap the given pointer is allocated on.
| |
| rpmalloc_get_heap_for_ptr | back to summary |
|---|---|
| public static long rpmalloc_get_heap_for_ptr(PointerBuffer ptr) Returns which heap the given pointer is allocated on.
| |
| rpmalloc_global_statistics | back to summary |
|---|---|
| public static void rpmalloc_global_statistics(RPmallocGlobalStatistics stats) Gets global statistics. | |
| rpmalloc_heap_acquire | back to summary |
|---|---|
| public static native long rpmalloc_heap_acquire() Acquires a new heap. Will reuse existing released heaps or allocate memory for a new heap if none available. Heap API is implemented with the strict assumption that only one single thread will call heap functions for a given heap at any given time, no functions are thread safe.
| |
| rpmalloc_heap_aligned_alloc | back to summary |
|---|---|
| public static ByteBuffer rpmalloc_heap_aligned_alloc(long heap, long alignment, long size) Allocates a memory block of at least the given size using the given heap. The returned block will have the requested alignment. Alignment must be a power of two and a multiple of
| |
| rpmalloc_heap_aligned_calloc | back to summary |
|---|---|
| public static ByteBuffer rpmalloc_heap_aligned_calloc(long heap, long alignment, long num, long size) Allocates a memory block of at least the given size using the given heap and zero initializes it. The returned block will have the requested alignment. Alignment must either be zero, or a power of two and a multiple of
| |
| rpmalloc_heap_aligned_realloc | back to summary |
|---|---|
| public static ByteBuffer rpmalloc_heap_aligned_realloc(long heap, ByteBuffer ptr, long alignment, long size, int flags) Reallocates the given block to at least the given size. The memory block MUST be allocated by the same heap given to this function. The returned block will have the requested alignment. Alignment must be
either zero, or a power of two and a multiple of
| |
| rpmalloc_heap_alloc | back to summary |
|---|---|
| public static ByteBuffer rpmalloc_heap_alloc(long heap, long size) Allocates a memory block of at least the given size using the given heap.
| |
| rpmalloc_heap_calloc | back to summary |
|---|---|
| public static ByteBuffer rpmalloc_heap_calloc(long heap, long num, long size) Allocates a memory block of at least the given size using the given heap and zero initializes it.
| |
| rpmalloc_heap_free | back to summary |
|---|---|
| public static void rpmalloc_heap_free(long heap, ByteBuffer ptr) Frees the given memory block from the given heap. The memory block MUST be allocated by the same heap given to this function. | |
| rpmalloc_heap_free | back to summary |
|---|---|
| public static void rpmalloc_heap_free(long heap, ShortBuffer ptr) Frees the given memory block from the given heap. The memory block MUST be allocated by the same heap given to this function. | |
| rpmalloc_heap_free | back to summary |
|---|---|
| public static void rpmalloc_heap_free(long heap, IntBuffer ptr) Frees the given memory block from the given heap. The memory block MUST be allocated by the same heap given to this function. | |
| rpmalloc_heap_free | back to summary |
|---|---|
| public static void rpmalloc_heap_free(long heap, LongBuffer ptr) Frees the given memory block from the given heap. The memory block MUST be allocated by the same heap given to this function. | |
| rpmalloc_heap_free | back to summary |
|---|---|
| public static void rpmalloc_heap_free(long heap, FloatBuffer ptr) Frees the given memory block from the given heap. The memory block MUST be allocated by the same heap given to this function. | |
| rpmalloc_heap_free | back to summary |
|---|---|
| public static void rpmalloc_heap_free(long heap, DoubleBuffer ptr) Frees the given memory block from the given heap. The memory block MUST be allocated by the same heap given to this function. | |
| rpmalloc_heap_free | back to summary |
|---|---|
| public static void rpmalloc_heap_free(long heap, PointerBuffer ptr) Frees the given memory block from the given heap. The memory block MUST be allocated by the same heap given to this function. | |
| rpmalloc_heap_free_all | back to summary |
|---|---|
| public static void rpmalloc_heap_free_all(long heap) Frees all memory allocated by the heap. | |
| rpmalloc_heap_realloc | back to summary |
|---|---|
| public static ByteBuffer rpmalloc_heap_realloc(long heap, ByteBuffer ptr, long size, int flags) Reallocates the given block to at least the given size. The memory block MUST be allocated by the same heap given to this function.
| |
| rpmalloc_heap_release | back to summary |
|---|---|
| public static native void rpmalloc_heap_release(long heap) Releases a heap (does NOT free the memory allocated by the heap, use Releasing a heap will enable it to be reused by other threads. Safe to pass a null pointer. | |
| rpmalloc_heap_thread_set_current | back to summary |
|---|---|
| public static native void rpmalloc_heap_thread_set_current(long heap) Sets the given heap as the current heap for the calling thread. A heap MUST only be current heap for a single thread, a heap can never be shared between multiple threads. The previous current heap for the calling thread is released to be reused by other threads. | |
| rpmalloc_initialize | back to summary |
|---|---|
| public static boolean rpmalloc_initialize() Initializes allocator with default configuration.
| |
| rpmalloc_initialize_config | back to summary |
|---|---|
| public static boolean rpmalloc_initialize_config(RPMallocConfig config) Initializes allocator with given configuration.
| |
| rpmalloc_is_thread_initialized | back to summary |
|---|---|
| public static boolean rpmalloc_is_thread_initialized() Query if allocator is initialized for calling thread.
| |
| rpmalloc_thread_collect | back to summary |
|---|---|
| public static native void rpmalloc_thread_collect() Performs deferred deallocations pending for the calling thread heap. | |
| rpmalloc_thread_finalize | back to summary |
|---|---|
| public static void rpmalloc_thread_finalize(boolean release_caches) Finalizes allocator for calling thread.
| |
| rpmalloc_thread_initialize | back to summary |
|---|---|
| public static native void rpmalloc_thread_initialize() Initializes allocator for calling thread. | |
| rpmalloc_thread_statistics | back to summary |
|---|---|
| public static void rpmalloc_thread_statistics(RPmallocThreadStatistics stats) Gets per-thread statistics. | |
| rpmalloc_usable_size | back to summary |
|---|---|
| public static long rpmalloc_usable_size(ByteBuffer ptr) Queries the usable size of the given memory block (from given pointer to the end of block).
| |
| rpmalloc_usable_size | back to summary |
|---|---|
| public static long rpmalloc_usable_size(ShortBuffer ptr) Queries the usable size of the given memory block (from given pointer to the end of block).
| |
| rpmalloc_usable_size | back to summary |
|---|---|
| public static long rpmalloc_usable_size(IntBuffer ptr) Queries the usable size of the given memory block (from given pointer to the end of block).
| |
| rpmalloc_usable_size | back to summary |
|---|---|
| public static long rpmalloc_usable_size(LongBuffer ptr) Queries the usable size of the given memory block (from given pointer to the end of block).
| |
| rpmalloc_usable_size | back to summary |
|---|---|
| public static long rpmalloc_usable_size(FloatBuffer ptr) Queries the usable size of the given memory block (from given pointer to the end of block).
| |
| rpmalloc_usable_size | back to summary |
|---|---|
| public static long rpmalloc_usable_size(DoubleBuffer ptr) Queries the usable size of the given memory block (from given pointer to the end of block).
| |
| rpmalloc_usable_size | back to summary |
|---|---|
| public static long rpmalloc_usable_size(PointerBuffer ptr) Queries the usable size of the given memory block (from given pointer to the end of block).
| |
| rpmemalign | back to summary |
|---|---|
| public static ByteBuffer rpmemalign(long alignment, long size) Allocates a memory block of at least the given size and alignment. Alignment must be a power of two and a multiple of
| |
| rpposix_memalign | back to summary |
|---|---|
| public static int rpposix_memalign(PointerBuffer memptr, long alignment, long size) Allocates a memory block of at least the given size and alignment. Alignment must be a power of two and a multiple of | |
| rprealloc | back to summary |
|---|---|
| public static ByteBuffer rprealloc(ByteBuffer ptr, long size) Reallocates the given block to at least the given size.
| |
| rprealloc_address | back to summary |
|---|---|
| pack-priv static native long rprealloc_address() The
| |