Extended functionality.
More...
Extended functionality.
◆ MI_SMALL_SIZE_MAX
#define MI_SMALL_SIZE_MAX |
◆ mi_deferred_free_fun
typedef void() mi_deferred_free_fun(bool force, unsigned long long heartbeat) |
Type of deferred free functions.
- Parameters
-
force | If true all outstanding items should be freed. |
heartbeat | A monotonically increasing count. |
- See also
- mi_register_deferred_free
◆ mi_output_fun
typedef void() mi_output_fun(const char *msg) |
◆ mi_collect()
void mi_collect |
( |
bool |
force | ) |
|
Eagerly free memory.
- Parameters
-
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.
◆ mi_good_size()
size_t mi_good_size |
( |
size_t |
size | ) |
|
Return the used allocation size.
- Parameters
-
size | The minimal required size in bytes. |
- Returns
- the size
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.
- See also
- mi_usable_size()
◆ mi_is_in_heap_region()
bool mi_is_in_heap_region |
( |
const void * |
p | ) |
|
Is a pointer part of our heap?
- Parameters
-
- Returns
- true if this is a pointer into our heap. This function is relatively fast.
◆ mi_is_redirected()
bool mi_is_redirected |
( |
| ) |
|
Is the C runtime malloc API redirected?
- Returns
- true if all malloc API calls are redirected to mimalloc.
Currenty only used on Windows.
◆ mi_malloc_small()
void* mi_malloc_small |
( |
size_t |
size | ) |
|
Allocate a small object.
- Parameters
-
- Returns
- a pointer to newly allocated memory of at least size bytes, or NULL if out of memory. This function is meant for use in run-time systems for best performance and does not check if size was indeed small – use with care!
◆ mi_register_deferred_free()
Register a deferred free function.
- Parameters
-
deferred_free | Address of a deferred free-ing function or NULL to unregister. |
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.
◆ mi_register_output()
Register an output function.
- Parameters
-
out | The output function, use NULL to output to stdout. |
The out
function is called to output any information from mimalloc, like verbose or warning messages.
◆ mi_reserve_huge_os_pages()
int mi_reserve_huge_os_pages |
( |
size_t |
pages, |
|
|
double |
max_secs, |
|
|
size_t * |
pages_reserved |
|
) |
| |
Reserve pages of huge OS pages (1GiB) but stops after at most max_secs
seconds.
- Parameters
-
pages | The number of 1GiB pages to reserve. |
max_secs | Maximum number of seconds to try reserving. |
pages_reserved | If not NULL, it is set to the actual number of pages that were reserved. |
- Returns
- 0 if successfull, ENOMEM if running out of memory, or ETIMEDOUT if timed out.
The reserved memory is used by mimalloc to satisfy allocations. May quit before max_secs are expired if it estimates it will take more than 1.5 times max_secs. 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.
◆ mi_stats_merge()
void mi_stats_merge |
( |
void |
| ) |
|
Merge thread local statistics with the main statistics and reset.
◆ mi_stats_print()
Print the main statistics.
- Parameters
-
out | Output function. Use NULL for outputting to stderr. |
Most detailed when using a debug build.
◆ mi_stats_reset()
void mi_stats_reset |
( |
void |
| ) |
|
◆ mi_thread_done()
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.
◆ mi_thread_init()
void mi_thread_init |
( |
void |
| ) |
|
Initialize mimalloc on a thread.
Should not be used as on most systems (pthreads, windows) this is done automatically.
◆ mi_thread_stats_print()
Print out heap statistics for this thread.
- Parameters
-
out | Output function. Use NULL for outputting to stderr. |
Most detailed when using a debug build.
◆ mi_usable_size()
size_t mi_usable_size |
( |
void * |
p | ) |
|
Return the available bytes in a memory block.
- Parameters
-
p | Pointer to previously allocated memory (or NULL) |
- Returns
- Returns the available bytes in the memory block, or 0 if p was 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.
- See also
- _msize (Windows)
-
malloc_usable_size (Linux)
-
mi_good_size()
◆ mi_zalloc_small()
void* mi_zalloc_small |
( |
size_t |
size | ) |
|
Allocate a zero initialized small object.
- Parameters
-
- Returns
- a pointer to newly allocated zero-initialized memory of at least size bytes, or NULL if out of memory. This function is meant for use in run-time systems for best performance and does not check if size was indeed small – use with care!