public class RPmalloc
extends java.lang.Object
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 |
|---|---|
static int |
RPMALLOC_NO_PRESERVE
Flag to
aligned_realloc to not preserve content in reallocation. |
| Modifier and Type | Method and Description |
|---|---|
static long |
nrpaligned_alloc(long alignment,
long size)
Unsafe version of:
aligned_alloc |
static long |
nrpaligned_realloc(long ptr,
long alignment,
long size,
long oldsize,
int flags)
Unsafe version of:
aligned_realloc |
static long |
nrpcalloc(long num,
long size)
Unsafe version of:
calloc |
static void |
nrpfree(long ptr)
Unsafe version of:
free |
static long |
nrpmalloc_config()
Unsafe version of:
malloc_config |
static void |
nrpmalloc_global_statistics(long stats)
Unsafe version of:
malloc_global_statistics |
static int |
nrpmalloc_initialize_config(long config)
Unsafe version of:
malloc_initialize_config |
static int |
nrpmalloc_initialize()
Unsafe version of:
malloc_initialize |
static int |
nrpmalloc_is_thread_initialized()
Unsafe version of:
malloc_is_thread_initialized |
static void |
nrpmalloc_thread_statistics(long stats)
Unsafe version of:
malloc_thread_statistics |
static long |
nrpmalloc_usable_size(long ptr)
Unsafe version of:
malloc_usable_size |
static long |
nrpmalloc(long size)
Unsafe version of:
malloc |
static long |
nrpmemalign(long alignment,
long size)
Unsafe version of:
memalign |
static int |
nrpposix_memalign(long memptr,
long alignment,
long size)
Unsafe version of:
posix_memalign |
static long |
nrprealloc(long ptr,
long size)
Unsafe version of:
realloc |
static java.nio.ByteBuffer |
rpaligned_alloc(long alignment,
long size)
Allocates a memory block of at least the given size and alignment.
|
static java.nio.ByteBuffer |
rpaligned_realloc(java.nio.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
MALLOC_NO_PRESERVE). |
static java.nio.ByteBuffer |
rpcalloc(long num,
long size)
Allocates a memory block of at least the given size and zero initializes it.
|
static void |
rpfree(java.nio.ByteBuffer ptr)
Frees the given memory block.
|
static void |
rpfree(java.nio.DoubleBuffer ptr)
Frees the given memory block.
|
static void |
rpfree(java.nio.FloatBuffer ptr)
Frees the given memory block.
|
static void |
rpfree(java.nio.IntBuffer ptr)
Frees the given memory block.
|
static void |
rpfree(java.nio.LongBuffer ptr)
Frees the given memory block.
|
static void |
rpfree(org.lwjgl.PointerBuffer ptr)
Frees the given memory block.
|
static void |
rpfree(java.nio.ShortBuffer ptr)
Frees the given memory block.
|
static RPMallocConfig |
rpmalloc_config()
Gets allocator configuration.
|
static void |
rpmalloc_finalize()
Finalizes allocator.
|
static void |
rpmalloc_global_statistics(RPmallocGlobalStatistics stats)
Gets global statistics.
|
static boolean |
rpmalloc_initialize_config(RPMallocConfig config)
Initializes allocator with given configuration.
|
static boolean |
rpmalloc_initialize()
Initializes allocator with default configuration.
|
static boolean |
rpmalloc_is_thread_initialized()
Query if allocator is initialized for calling thread.
|
static void |
rpmalloc_thread_collect()
Performs deferred deallocations pending for the calling thread heap.
|
static void |
rpmalloc_thread_finalize()
Finalizes allocator for calling thread.
|
static void |
rpmalloc_thread_initialize()
Initializes allocator for calling thread.
|
static void |
rpmalloc_thread_statistics(RPmallocThreadStatistics stats)
Gets per-thread statistics.
|
static long |
rpmalloc_usable_size(java.nio.ByteBuffer ptr)
Queries the usable size of the given memory block (from given pointer to the end of block).
|
static long |
rpmalloc_usable_size(java.nio.DoubleBuffer ptr)
Queries the usable size of the given memory block (from given pointer to the end of block).
|
static long |
rpmalloc_usable_size(java.nio.FloatBuffer ptr)
Queries the usable size of the given memory block (from given pointer to the end of block).
|
static long |
rpmalloc_usable_size(java.nio.IntBuffer ptr)
Queries the usable size of the given memory block (from given pointer to the end of block).
|
static long |
rpmalloc_usable_size(java.nio.LongBuffer ptr)
Queries the usable size of the given memory block (from given pointer to the end of block).
|
static long |
rpmalloc_usable_size(org.lwjgl.PointerBuffer ptr)
Queries the usable size of the given memory block (from given pointer to the end of block).
|
static long |
rpmalloc_usable_size(java.nio.ShortBuffer ptr)
Queries the usable size of the given memory block (from given pointer to the end of block).
|
static java.nio.ByteBuffer |
rpmalloc(long size)
Allocates a memory block of at least the given size.
|
static java.nio.ByteBuffer |
rpmemalign(long alignment,
long size)
Allocates a memory block of at least the given size and alignment.
|
static int |
rpposix_memalign(org.lwjgl.PointerBuffer memptr,
long alignment,
long size)
Allocates a memory block of at least the given size and alignment.
|
static java.nio.ByteBuffer |
rprealloc(java.nio.ByteBuffer ptr,
long size)
Reallocates the given block to at least the given size.
|
public static final int RPMALLOC_NO_PRESERVE
aligned_realloc to not preserve content in reallocation.public static int nrpmalloc_initialize()
malloc_initializepublic static boolean rpmalloc_initialize()
public static int nrpmalloc_initialize_config(long config)
malloc_initialize_configpublic static boolean rpmalloc_initialize_config(@Nullable
RPMallocConfig config)
config - an optional RPMallocConfig instancepublic static long nrpmalloc_config()
malloc_configpublic static RPMallocConfig rpmalloc_config()
public static void rpmalloc_finalize()
public static void rpmalloc_thread_initialize()
public static void rpmalloc_thread_finalize()
public static void rpmalloc_thread_collect()
public static int nrpmalloc_is_thread_initialized()
malloc_is_thread_initializedpublic static boolean rpmalloc_is_thread_initialized()
public static void nrpmalloc_thread_statistics(long stats)
malloc_thread_statisticspublic static void rpmalloc_thread_statistics(RPmallocThreadStatistics stats)
public static void nrpmalloc_global_statistics(long stats)
malloc_global_statisticspublic static void rpmalloc_global_statistics(RPmallocGlobalStatistics stats)
public static long nrpmalloc(long size)
malloc@Nullable public static java.nio.ByteBuffer rpmalloc(long size)
public static void nrpfree(long ptr)
freepublic static void rpfree(@Nullable
java.nio.ByteBuffer ptr)
public static void rpfree(@Nullable
java.nio.ShortBuffer ptr)
public static void rpfree(@Nullable
java.nio.IntBuffer ptr)
public static void rpfree(@Nullable
java.nio.LongBuffer ptr)
public static void rpfree(@Nullable
java.nio.FloatBuffer ptr)
public static void rpfree(@Nullable
java.nio.DoubleBuffer ptr)
public static void rpfree(@Nullable
org.lwjgl.PointerBuffer ptr)
public static long nrpcalloc(long num,
long size)
calloc@Nullable
public static java.nio.ByteBuffer rpcalloc(long num,
long size)
public static long nrprealloc(long ptr,
long size)
realloc@Nullable
public static java.nio.ByteBuffer rprealloc(@Nullable
java.nio.ByteBuffer ptr,
long size)
public static long nrpaligned_realloc(long ptr,
long alignment,
long size,
long oldsize,
int flags)
aligned_realloc@Nullable
public static java.nio.ByteBuffer rpaligned_realloc(@Nullable
java.nio.ByteBuffer ptr,
long alignment,
long size,
int flags)
MALLOC_NO_PRESERVE).
Alignment must be a power of two and a multiple of sizeof(void*), and should ideally be less than memory page size. A caveat of rpmalloc
internals is that this must also be strictly less than the span size (default 64KiB).
public static long nrpaligned_alloc(long alignment,
long size)
aligned_alloc@Nullable
public static java.nio.ByteBuffer rpaligned_alloc(long alignment,
long size)
Alignment must be a power of two and a multiple of sizeof(void*), and should ideally be less than memory page size. A caveat of rpmalloc
internals is that this must also be strictly less than the span size (default 64KiB).
public static long nrpmemalign(long alignment,
long size)
memalign@Nullable
public static java.nio.ByteBuffer rpmemalign(long alignment,
long size)
Alignment must be a power of two and a multiple of sizeof(void*), and should ideally be less than memory page size. A caveat of rpmalloc
internals is that this must also be strictly less than the span size (default 64KiB).
public static int nrpposix_memalign(long memptr,
long alignment,
long size)
posix_memalignpublic static int rpposix_memalign(org.lwjgl.PointerBuffer memptr,
long alignment,
long size)
Alignment must be a power of two and a multiple of sizeof(void*), and should ideally be less than memory page size. A caveat of rpmalloc
internals is that this must also be strictly less than the span size (default 64KiB).
public static long nrpmalloc_usable_size(long ptr)
malloc_usable_sizepublic static long rpmalloc_usable_size(java.nio.ByteBuffer ptr)
public static long rpmalloc_usable_size(java.nio.ShortBuffer ptr)
public static long rpmalloc_usable_size(java.nio.IntBuffer ptr)
public static long rpmalloc_usable_size(java.nio.LongBuffer ptr)
public static long rpmalloc_usable_size(java.nio.FloatBuffer ptr)
public static long rpmalloc_usable_size(java.nio.DoubleBuffer ptr)
public static long rpmalloc_usable_size(org.lwjgl.PointerBuffer ptr)
Copyright LWJGL. All Rights Reserved. License terms.