Extended functionality. More...
Macros | |
#define | MI_SMALL_SIZE_MAX |
Maximum size allowed for small allocations in mi_malloc_small and mi_zalloc_small (usually 128*sizeof(void*) (= 1KB on 64-bit systems)) More... | |
Typedefs | |
typedef void() | mi_deferred_free_fun(bool force, unsigned long long heartbeat, void *arg) |
Type of deferred free functions. More... | |
typedef void() | mi_output_fun(const char *msg, void *arg) |
Type of output functions. More... | |
typedef void() | mi_error_fun(int err, void *arg) |
Type of error callback functions. More... | |
Functions | |
void * | mi_malloc_small (size_t size) |
Allocate a small object. More... | |
void * | mi_zalloc_small (size_t size) |
Allocate a zero initialized small object. More... | |
size_t | mi_usable_size (void *p) |
Return the available bytes in a memory block. More... | |
size_t | mi_good_size (size_t size) |
Return the used allocation size. More... | |
void | mi_collect (bool force) |
Eagerly free memory. More... | |
void | mi_stats_print (void *out) |
Deprecated. More... | |
void | mi_stats_print_out (mi_output_fun *out, void *arg) |
Print the main statistics. More... | |
void | mi_stats_reset (void) |
Reset statistics. More... | |
void | mi_stats_merge (void) |
Merge thread local statistics with the main statistics and reset. More... | |
void | mi_thread_init (void) |
Initialize mimalloc on a thread. More... | |
void | mi_thread_done (void) |
Uninitialize mimalloc on a thread. More... | |
void | mi_thread_stats_print_out (mi_output_fun *out, void *arg) |
Print out heap statistics for this thread. More... | |
void | mi_register_deferred_free (mi_deferred_free_fun *deferred_free, void *arg) |
Register a deferred free function. More... | |
void | mi_register_output (mi_output_fun *out, void *arg) |
Register an output function. More... | |
void | mi_register_error (mi_error_fun *errfun, void *arg) |
Register an error callback function. More... | |
bool | mi_is_in_heap_region (const void *p) |
Is a pointer part of our heap? More... | |
int | mi_reserve_huge_os_pages_interleave (size_t pages, size_t numa_nodes, size_t timeout_msecs) |
Reserve pages of huge OS pages (1GiB) evenly divided over numa_nodes nodes, but stops after at most timeout_msecs seconds. More... | |
int | mi_reserve_huge_os_pages_at (size_t pages, int numa_node, size_t timeout_msecs) |
Reserve pages of huge OS pages (1GiB) at a specific numa_node, but stops after at most timeout_msecs seconds. More... | |
bool | mi_is_redirected () |
Is the C runtime malloc API redirected? More... | |
Extended functionality.
#define MI_SMALL_SIZE_MAX |
Maximum size allowed for small allocations in mi_malloc_small and mi_zalloc_small (usually 128*sizeof(void*)
(= 1KB on 64-bit systems))
typedef void() mi_deferred_free_fun(bool force, unsigned long long heartbeat, void *arg) |
Type of deferred free functions.
force | If true all outstanding items should be freed. |
heartbeat | A monotonically increasing count. |
arg | Argument that was passed at registration to hold extra state. |
typedef void() mi_error_fun(int err, void *arg) |
Type of error callback functions.
err | Error code (see mi_register_error() for a complete list). |
arg | Argument that was passed at registration to hold extra state. |
typedef void() mi_output_fun(const char *msg, void *arg) |
Type of output functions.
msg | Message to output. |
arg | Argument that was passed at registration to hold extra state. |
void mi_collect | ( | bool | force | ) |
Eagerly free memory.
force | If true, aggressively return memory to the OS (can be expensive!) |
Regular code should not have to call this function. It can be beneficial in very narrow circumstances; in particular, when a long running thread allocates a lot of blocks that are freed by other threads it may improve resource usage by calling this every once in a while.
size_t mi_good_size | ( | size_t | size | ) |
Return the used allocation size.
size | The minimal required size in bytes. |
n
that will be allocated, where n >= size
.Generally, mi_usable_size(mi_malloc(size)) == mi_good_size(size)
. This can be used to reduce internal wasted space when allocating buffers for example.
bool mi_is_in_heap_region | ( | const void * | p | ) |
Is a pointer part of our heap?
p | The pointer to check. |
bool mi_is_redirected | ( | ) |
Is the C runtime malloc API redirected?
Currenty only used on Windows.
void* mi_malloc_small | ( | size_t | size | ) |
Allocate a small object.
size | The size in bytes, can be at most MI_SMALL_SIZE_MAX. |
void mi_register_deferred_free | ( | mi_deferred_free_fun * | deferred_free, |
void * | arg | ||
) |
Register a deferred free function.
deferred_free | Address of a deferred free-ing function or NULL to unregister. |
arg | Argument that will be passed on to the deferred free function. |
Some runtime systems use deferred free-ing, for example when using reference counting to limit the worst case free time. Such systems can register (re-entrant) deferred free function to free more memory on demand. When the force parameter is true all possible memory should be freed. The per-thread heartbeat parameter is monotonically increasing and guaranteed to be deterministic if the program allocates deterministically. The deferred_free function is guaranteed to be called deterministically after some number of allocations (regardless of freeing or available free memory). At most one deferred_free function can be active.
void mi_register_error | ( | mi_error_fun * | errfun, |
void * | arg | ||
) |
Register an error callback function.
errfun | The error function that is called on an error (use NULL for default) |
arg | Extra argument that will be passed on to the error function. |
The errfun function is called on an error in mimalloc after emitting an error message (through the output function). It as always legal to just return from the errfun function in which case allocation functions generally return NULL or ignore the condition. The default function only calls abort() when compiled in secure mode with an EFAULT error. The possible error codes are:
void mi_register_output | ( | mi_output_fun * | out, |
void * | arg | ||
) |
Register an output function.
out | The output function, use NULL to output to stderr. |
arg | Argument that will be passed on to the output function. |
The out
function is called to output any information from mimalloc, like verbose or warning messages.
int mi_reserve_huge_os_pages_at | ( | size_t | pages, |
int | numa_node, | ||
size_t | timeout_msecs | ||
) |
Reserve pages of huge OS pages (1GiB) at a specific numa_node, but stops after at most timeout_msecs
seconds.
pages | The number of 1GiB pages to reserve. |
numa_node | The NUMA node where the memory is reserved (start at 0). |
timeout_msecs | Maximum number of milli-seconds to try reserving, or 0 for no timeout. |
The reserved memory is used by mimalloc to satisfy allocations. May quit before timeout_msecs are expired if it estimates it will take more than 1.5 times timeout_msecs. The time limit is needed because on some operating systems it can take a long time to reserve contiguous memory if the physical memory is fragmented.
int mi_reserve_huge_os_pages_interleave | ( | size_t | pages, |
size_t | numa_nodes, | ||
size_t | timeout_msecs | ||
) |
Reserve pages of huge OS pages (1GiB) evenly divided over numa_nodes nodes, but stops after at most timeout_msecs
seconds.
pages | The number of 1GiB pages to reserve. |
numa_nodes | The number of nodes do evenly divide the pages over, or 0 for using the actual number of NUMA nodes. |
timeout_msecs | Maximum number of milli-seconds to try reserving, or 0 for no timeout. |
The reserved memory is used by mimalloc to satisfy allocations. May quit before timeout_msecs are expired if it estimates it will take more than 1.5 times timeout_msecs. The time limit is needed because on some operating systems it can take a long time to reserve contiguous memory if the physical memory is fragmented.
void mi_stats_merge | ( | void | ) |
Merge thread local statistics with the main statistics and reset.
void mi_stats_print | ( | void * | out | ) |
Deprecated.
out | Ignored, outputs to the registered output function or stderr by default. |
Most detailed when using a debug build.
void mi_stats_print_out | ( | mi_output_fun * | out, |
void * | arg | ||
) |
Print the main statistics.
out | An output function or NULL for the default. |
arg | Optional argument passed to out (if not NULL) |
Most detailed when using a debug build.
void mi_stats_reset | ( | void | ) |
Reset statistics.
void mi_thread_done | ( | void | ) |
Uninitialize mimalloc on a thread.
Should not be used as on most systems (pthreads, windows) this is done automatically. Ensures that any memory that is not freed yet (but will be freed by other threads in the future) is properly handled.
void mi_thread_init | ( | void | ) |
Initialize mimalloc on a thread.
Should not be used as on most systems (pthreads, windows) this is done automatically.
void mi_thread_stats_print_out | ( | mi_output_fun * | out, |
void * | arg | ||
) |
Print out heap statistics for this thread.
out | An output function or NULL for the default. |
arg | Optional argument passed to out (if not NULL) |
Most detailed when using a debug build.
size_t mi_usable_size | ( | void * | p | ) |
Return the available bytes in a memory block.
p | Pointer to previously allocated memory (or NULL) |
The returned size can be used to call mi_expand successfully. The returned size is always at least equal to the allocated size of p, and, in the current design, should be less than 16.7% more.
void* mi_zalloc_small | ( | size_t | size | ) |
Allocate a zero initialized small object.
size | The size in bytes, can be at most MI_SMALL_SIZE_MAX. |