First-class heaps. More...
Typedefs | |
| typedef struct mi_heap_s | mi_heap_t |
| Type of first-class heaps. | |
Functions | |
| mi_heap_t * | mi_heap_new () |
| Create a new heap that can be used for allocation. | |
| void | mi_heap_delete (mi_heap_t *heap) |
| Delete a previously allocated heap. | |
| void | mi_heap_destroy (mi_heap_t *heap) |
| Destroy a heap, freeing all its still allocated blocks. | |
| mi_heap_t * | mi_heap_set_default (mi_heap_t *heap) |
| v1,v2: Set the default heap to use in the current thread for mi_malloc() et al. | |
| mi_heap_t * | mi_heap_get_default () |
| v1,v2: Get the default heap that is used for mi_malloc() et al. | |
| mi_heap_t * | mi_heap_get_backing () |
| v1,v2: Get the backing heap. | |
| void | mi_heap_set_numa_affinity (mi_heap_t *heap, int numa_node) |
| v3: set NUMA affinity for a heap. | |
| mi_heap_t * | mi_heap_main (void) |
| v3: the main heap (of the current sub-process) | |
| mi_heap_t * | mi_heap_of (const void *p) |
| v3: return the heap that contains the given pointer. | |
| bool | mi_heap_contains (const mi_heap_t *heap, const void *p) |
| v3: does a heap contain a specific pointer? | |
| bool | mi_any_heap_contains (const void *p) |
| v3: is a pointer pointing into mimalloc managed memory? | |
| bool | mi_is_in_heap_region (const void *p) |
| v1,v2: Is a pointer part of our heap? | |
| bool | mi_check_owned (const void *p) |
| v1,v2: Check if any pointer is part of the default heap of this thread. | |
| bool | mi_heap_contains_block (mi_heap_t *heap, const void *p) |
| v1,v2: Does a heap contain a pointer to a previously allocated block? | |
| bool | mi_heap_check_owned (mi_heap_t *heap, const void *p) |
| v1,v2: Check safely if any pointer is part of a heap. | |
| void | mi_heap_collect (mi_heap_t *heap, bool force) |
| Release outstanding resources in a specific heap. | |
| void * | mi_heap_malloc (mi_heap_t *heap, size_t size) |
| Allocate in a specific heap. | |
| void * | mi_heap_malloc_small (mi_heap_t *heap, size_t size) |
| Allocate a small object in a specific heap. | |
| void * | mi_heap_zalloc (mi_heap_t *heap, size_t size) |
| Allocate zero-initialized in a specific heap. | |
| void * | mi_heap_calloc (mi_heap_t *heap, size_t count, size_t size) |
| Allocate count zero-initialized elements in a specific heap. | |
| void * | mi_heap_mallocn (mi_heap_t *heap, size_t count, size_t size) |
| Allocate count elements in a specific heap. | |
| char * | mi_heap_strdup (mi_heap_t *heap, const char *s) |
| Duplicate a string in a specific heap. | |
| char * | mi_heap_strndup (mi_heap_t *heap, const char *s, size_t n) |
| Duplicate a string of at most length n in a specific heap. | |
| char * | mi_heap_realpath (mi_heap_t *heap, const char *fname, char *resolved_name) |
| Resolve a file path name using a specific heap to allocate the result. | |
| void * | mi_heap_realloc (mi_heap_t *heap, void *p, size_t newsize) |
| void * | mi_heap_reallocn (mi_heap_t *heap, void *p, size_t count, size_t size) |
| void * | mi_heap_reallocf (mi_heap_t *heap, void *p, size_t newsize) |
| void * | mi_heap_malloc_aligned (mi_heap_t *heap, size_t size, size_t alignment) |
| void * | mi_heap_malloc_aligned_at (mi_heap_t *heap, size_t size, size_t alignment, size_t offset) |
| void * | mi_heap_zalloc_aligned (mi_heap_t *heap, size_t size, size_t alignment) |
| void * | mi_heap_zalloc_aligned_at (mi_heap_t *heap, size_t size, size_t alignment, size_t offset) |
| void * | mi_heap_calloc_aligned (mi_heap_t *heap, size_t count, size_t size, size_t alignment) |
| void * | mi_heap_calloc_aligned_at (mi_heap_t *heap, size_t count, size_t size, size_t alignment, size_t offset) |
| void * | mi_heap_realloc_aligned (mi_heap_t *heap, void *p, size_t newsize, size_t alignment) |
| void * | mi_heap_realloc_aligned_at (mi_heap_t *heap, void *p, size_t newsize, size_t alignment, size_t offset) |
First-class heaps.
Heaps allow allocations to be grouped, and for example be destroyed in one go. Heaps can also be associated with a specific allocation arena (mi_heap_new_in_arena()).
v1,v2: heaps are only semi-first-class and one can only use heap allocation functions from the thread that created the heap. (of course, mi_free() can always be used from any thread to free objects from any heap).
v3: heaps are fully first-class and can be used to allocate efficiently from from any thread. In v3, the old v1/v2 heaps still exist but are now called theaps (mi_theap_t()) for thread-local heaps. A v3 heap creates internally such theaps on demand to efficiently allocate without needing taking locks for example.
| typedef struct mi_heap_s mi_heap_t |
Type of first-class heaps.
v1,v2: in mimalloc v1 and v2, a heap can only be used for allocation in the thread that created this heap!
| bool mi_any_heap_contains | ( | const void * | p | ) |
v3: is a pointer pointing into mimalloc managed memory?
| p | Any pointer – not required to be previously allocated by mimalloc. This is a constant time efficient function. |
| bool mi_check_owned | ( | const void * | p | ) |
v1,v2: Check if any pointer is part of the default heap of this thread.
| p | Any pointer – not required to be previously allocated by us. |
| void * mi_heap_calloc | ( | mi_heap_t * | heap, |
| size_t | count, | ||
| size_t | size ) |
Allocate count zero-initialized elements in a specific heap.
| void * mi_heap_calloc_aligned | ( | mi_heap_t * | heap, |
| size_t | count, | ||
| size_t | size, | ||
| size_t | alignment ) |
| void * mi_heap_calloc_aligned_at | ( | mi_heap_t * | heap, |
| size_t | count, | ||
| size_t | size, | ||
| size_t | alignment, | ||
| size_t | offset ) |
| bool mi_heap_check_owned | ( | mi_heap_t * | heap, |
| const void * | p ) |
v1,v2: Check safely if any pointer is part of a heap.
| heap | The heap. |
| p | Any pointer – not required to be previously allocated by us. |
| void mi_heap_collect | ( | mi_heap_t * | heap, |
| bool | force ) |
Release outstanding resources in a specific heap.
| bool mi_heap_contains | ( | const mi_heap_t * | heap, |
| const void * | p ) |
v3: does a heap contain a specific pointer?
| heap | The heap to query. |
| p | Any pointer – not required to be previously allocated by mimalloc. This is a constant time efficient function. |
| bool mi_heap_contains_block | ( | mi_heap_t * | heap, |
| const void * | p ) |
v1,v2: Does a heap contain a pointer to a previously allocated block?
| heap | The heap. |
| p | Pointer to a previously allocated block (in any heap)– cannot be some random pointer! |
| void mi_heap_delete | ( | mi_heap_t * | heap | ) |
Delete a previously allocated heap.
This will release internal resources but not free still allocated blocks in this heap (and should be mi_free'd later on as usual).
Note: trying to delete the main heap of a subprocess is ignored.
| void mi_heap_destroy | ( | mi_heap_t * | heap | ) |
Destroy a heap, freeing all its still allocated blocks.
Use with care as this will free all blocks still allocated in the heap. However, this can be an efficient way to free all heap memory in one go.
Note: trying to destroy the main heap of a subprocess is ignored.
| mi_heap_t * mi_heap_get_backing | ( | ) |
v1,v2: Get the backing heap.
The backing heap is the initial default heap for a thread and always available for allocations. It cannot be destroyed or deleted except by exiting the thread.
| mi_heap_t * mi_heap_get_default | ( | ) |
v1,v2: Get the default heap that is used for mi_malloc() et al.
(for the current thread).
| mi_heap_t * mi_heap_main | ( | void | ) |
v3: the main heap (of the current sub-process)
| void * mi_heap_malloc | ( | mi_heap_t * | heap, |
| size_t | size ) |
Allocate in a specific heap.
| void * mi_heap_malloc_aligned | ( | mi_heap_t * | heap, |
| size_t | size, | ||
| size_t | alignment ) |
| void * mi_heap_malloc_aligned_at | ( | mi_heap_t * | heap, |
| size_t | size, | ||
| size_t | alignment, | ||
| size_t | offset ) |
| void * mi_heap_malloc_small | ( | mi_heap_t * | heap, |
| size_t | size ) |
Allocate a small object in a specific heap.
size must be smaller or equal to MI_SMALL_SIZE_MAX().
| void * mi_heap_mallocn | ( | mi_heap_t * | heap, |
| size_t | count, | ||
| size_t | size ) |
Allocate count elements in a specific heap.
| mi_heap_t * mi_heap_new | ( | ) |
Create a new heap that can be used for allocation.
| mi_heap_t * mi_heap_of | ( | const void * | p | ) |
v3: return the heap that contains the given pointer.
| p | Any pointer – not required to be previously allocated by mimalloc. |
NULL if the pointer does not point into mimalloc allocated memory. This is a constant time efficient function. | void * mi_heap_realloc | ( | mi_heap_t * | heap, |
| void * | p, | ||
| size_t | newsize ) |
| void * mi_heap_realloc_aligned | ( | mi_heap_t * | heap, |
| void * | p, | ||
| size_t | newsize, | ||
| size_t | alignment ) |
| void * mi_heap_realloc_aligned_at | ( | mi_heap_t * | heap, |
| void * | p, | ||
| size_t | newsize, | ||
| size_t | alignment, | ||
| size_t | offset ) |
| void * mi_heap_reallocf | ( | mi_heap_t * | heap, |
| void * | p, | ||
| size_t | newsize ) |
| void * mi_heap_reallocn | ( | mi_heap_t * | heap, |
| void * | p, | ||
| size_t | count, | ||
| size_t | size ) |
| char * mi_heap_realpath | ( | mi_heap_t * | heap, |
| const char * | fname, | ||
| char * | resolved_name ) |
Resolve a file path name using a specific heap to allocate the result.
v1,v2: Set the default heap to use in the current thread for mi_malloc() et al.
| heap | The new default heap. |
| void mi_heap_set_numa_affinity | ( | mi_heap_t * | heap, |
| int | numa_node ) |
v3: set NUMA affinity for a heap.
| heap | the heap which should be associated with a specific numa node. |
| numa_node | the numa node to associate to (>=0) |
| char * mi_heap_strdup | ( | mi_heap_t * | heap, |
| const char * | s ) |
Duplicate a string in a specific heap.
| char * mi_heap_strndup | ( | mi_heap_t * | heap, |
| const char * | s, | ||
| size_t | n ) |
Duplicate a string of at most length n in a specific heap.
| void * mi_heap_zalloc | ( | mi_heap_t * | heap, |
| size_t | size ) |
Allocate zero-initialized in a specific heap.
| void * mi_heap_zalloc_aligned | ( | mi_heap_t * | heap, |
| size_t | size, | ||
| size_t | alignment ) |
| void * mi_heap_zalloc_aligned_at | ( | mi_heap_t * | heap, |
| size_t | size, | ||
| size_t | alignment, | ||
| size_t | offset ) |
| bool mi_is_in_heap_region | ( | const void * | p | ) |
v1,v2: Is a pointer part of our heap?
| p | The pointer to check. |