mi-malloc: mimalloc-doc.h Source File

| mi-malloc 1.8/2.1 |

Loading...
Searching...
No Matches
mimalloc-doc.h
1/* ----------------------------------------------------------------------------
2Copyright (c) 2018-2025, Microsoft Research, Daan Leijen
3This is free software; you can redistribute it and/or modify it under the
4terms of the MIT license. A copy of the license can be found in the file
5"LICENSE" at the root of this distribution.
6-----------------------------------------------------------------------------*/
7
8#error "documentation file only!"
9
10
92
93
97
98
102 void mi_free(void* p);
103
108 void* mi_malloc(size_t size);
109
114 void* mi_zalloc(size_t size);
115
125 void* mi_calloc(size_t count, size_t size);
126
139 void* mi_realloc(void* p, size_t newsize);
140
151 void* mi_recalloc(void* p, size_t count, size_t size);
152
166 void* mi_expand(void* p, size_t newsize);
167
177 void* mi_mallocn(size_t count, size_t size);
178
188 void* mi_reallocn(void* p, size_t count, size_t size);
189
206 void* mi_reallocf(void* p, size_t newsize);
207
208
217 char* mi_strdup(const char* s);
218
228 char* mi_strndup(const char* s, size_t n);
229
242 char* mi_realpath(const char* fname, char* resolved_name);
243
245
246// ------------------------------------------------------
247// Extended functionality
248// ------------------------------------------------------
249
253
256#define MI_SMALL_SIZE_MAX (128*sizeof(void*))
257
265 void* mi_malloc_small(size_t size);
266
274 void* mi_zalloc_small(size_t size);
275
289 size_t mi_usable_size(void* p);
290
300 size_t mi_good_size(size_t size);
301
309 void mi_collect(bool force);
310
315 void mi_stats_print(void* out);
316
322 void mi_stats_print_out(mi_output_fun* out, void* arg);
323
325 void mi_stats_reset(void);
326
328 void mi_stats_merge(void);
329
333 void mi_thread_init(void);
334
339 void mi_thread_done(void);
340
346 void mi_thread_stats_print_out(mi_output_fun* out, void* arg);
347
354 typedef void (mi_deferred_free_fun)(bool force, unsigned long long heartbeat, void* arg);
355
371 void mi_register_deferred_free(mi_deferred_free_fun* deferred_free, void* arg);
372
378 typedef void (mi_output_fun)(const char* msg, void* arg);
379
386 void mi_register_output(mi_output_fun* out, void* arg);
387
393 typedef void (mi_error_fun)(int err, void* arg);
394
410 void mi_register_error(mi_error_fun* errfun, void* arg);
411
416 bool mi_is_in_heap_region(const void* p);
417
426 int mi_reserve_os_memory(size_t size, bool commit, bool allow_large);
427
439 bool mi_manage_os_memory(void* start, size_t size, bool is_committed, bool is_large, bool is_zero, int numa_node);
440
453 int mi_reserve_huge_os_pages_interleave(size_t pages, size_t numa_nodes, size_t timeout_msecs);
454
467 int mi_reserve_huge_os_pages_at(size_t pages, int numa_node, size_t timeout_msecs);
468
469
474 bool mi_is_redirected();
475
489 void mi_process_info(size_t* elapsed_msecs, size_t* user_msecs, size_t* system_msecs, size_t* current_rss, size_t* peak_rss, size_t* current_commit, size_t* peak_commit, size_t* page_faults);
490
495 void mi_debug_show_arenas(bool show_inuse, bool show_abandoned, bool show_purge);
496
499 typedef int mi_arena_id_t;
500
505 void* mi_arena_area(mi_arena_id_t arena_id, size_t* size);
506
514 int mi_reserve_huge_os_pages_at_ex(size_t pages, int numa_node, size_t timeout_msecs, bool exclusive, mi_arena_id_t* arena_id);
515
523 int mi_reserve_os_memory_ex(size_t size, bool commit, bool allow_large, bool exclusive, mi_arena_id_t* arena_id);
524
535 bool mi_manage_os_memory_ex(void* start, size_t size, bool is_committed, bool is_large, bool is_zero, int numa_node, bool exclusive, mi_arena_id_t* arena_id);
536
540 mi_heap_t* mi_heap_new_in_arena(mi_arena_id_t arena_id);
541
552 mi_heap_t* mi_heap_new_ex(int heap_tag, bool allow_destroy, mi_arena_id_t arena_id);
553
557 typedef void* mi_subproc_id_t;
558
560 mi_subproc_id_t mi_subproc_main(void);
561
564 mi_subproc_id_t mi_subproc_new(void);
565
569 void mi_subproc_delete(mi_subproc_id_t subproc);
570
573 void mi_subproc_add_current_thread(mi_subproc_id_t subproc);
574
575
577
578// ------------------------------------------------------
579// Aligned allocation
580// ------------------------------------------------------
581
589
607 void* mi_malloc_aligned(size_t size, size_t alignment);
608 void* mi_zalloc_aligned(size_t size, size_t alignment);
609 void* mi_calloc_aligned(size_t count, size_t size, size_t alignment);
610 void* mi_realloc_aligned(void* p, size_t newsize, size_t alignment);
611
623 void* mi_malloc_aligned_at(size_t size, size_t alignment, size_t offset);
624 void* mi_zalloc_aligned_at(size_t size, size_t alignment, size_t offset);
625 void* mi_calloc_aligned_at(size_t count, size_t size, size_t alignment, size_t offset);
626 void* mi_realloc_aligned_at(void* p, size_t newsize, size_t alignment, size_t offset);
627
629
635
640struct mi_heap_s;
641
646 typedef struct mi_heap_s mi_heap_t;
647
649 mi_heap_t* mi_heap_new();
650
658 void mi_heap_delete(mi_heap_t* heap);
659
667 void mi_heap_destroy(mi_heap_t* heap);
668
672 mi_heap_t* mi_heap_set_default(mi_heap_t* heap);
673
676 mi_heap_t* mi_heap_get_default();
677
683 mi_heap_t* mi_heap_get_backing();
684
686 void mi_heap_collect(mi_heap_t* heap, bool force);
687
690 void* mi_heap_malloc(mi_heap_t* heap, size_t size);
691
695 void* mi_heap_malloc_small(mi_heap_t* heap, size_t size);
696
699 void* mi_heap_zalloc(mi_heap_t* heap, size_t size);
700
703 void* mi_heap_calloc(mi_heap_t* heap, size_t count, size_t size);
704
707 void* mi_heap_mallocn(mi_heap_t* heap, size_t count, size_t size);
708
711 char* mi_heap_strdup(mi_heap_t* heap, const char* s);
712
715 char* mi_heap_strndup(mi_heap_t* heap, const char* s, size_t n);
716
719 char* mi_heap_realpath(mi_heap_t* heap, const char* fname, char* resolved_name);
720
721 void* mi_heap_realloc(mi_heap_t* heap, void* p, size_t newsize);
722 void* mi_heap_reallocn(mi_heap_t* heap, void* p, size_t count, size_t size);
723 void* mi_heap_reallocf(mi_heap_t* heap, void* p, size_t newsize);
724
725 void* mi_heap_malloc_aligned(mi_heap_t* heap, size_t size, size_t alignment);
726 void* mi_heap_malloc_aligned_at(mi_heap_t* heap, size_t size, size_t alignment, size_t offset);
727 void* mi_heap_zalloc_aligned(mi_heap_t* heap, size_t size, size_t alignment);
728 void* mi_heap_zalloc_aligned_at(mi_heap_t* heap, size_t size, size_t alignment, size_t offset);
729 void* mi_heap_calloc_aligned(mi_heap_t* heap, size_t count, size_t size, size_t alignment);
730 void* mi_heap_calloc_aligned_at(mi_heap_t* heap, size_t count, size_t size, size_t alignment, size_t offset);
731 void* mi_heap_realloc_aligned(mi_heap_t* heap, void* p, size_t newsize, size_t alignment);
732 void* mi_heap_realloc_aligned_at(mi_heap_t* heap, void* p, size_t newsize, size_t alignment, size_t offset);
733
735
736
745
746 void* mi_rezalloc(void* p, size_t newsize);
747void* mi_recalloc(void* p, size_t newcount, size_t size) ;
748
749 void* mi_rezalloc_aligned(void* p, size_t newsize, size_t alignment);
750 void* mi_rezalloc_aligned_at(void* p, size_t newsize, size_t alignment, size_t offset);
751 void* mi_recalloc_aligned(void* p, size_t newcount, size_t size, size_t alignment);
752 void* mi_recalloc_aligned_at(void* p, size_t newcount, size_t size, size_t alignment, size_t offset);
753
754 void* mi_heap_rezalloc(mi_heap_t* heap, void* p, size_t newsize);
755 void* mi_heap_recalloc(mi_heap_t* heap, void* p, size_t newcount, size_t size);
756
757 void* mi_heap_rezalloc_aligned(mi_heap_t* heap, void* p, size_t newsize, size_t alignment);
758 void* mi_heap_rezalloc_aligned_at(mi_heap_t* heap, void* p, size_t newsize, size_t alignment, size_t offset);
759 void* mi_heap_recalloc_aligned(mi_heap_t* heap, void* p, size_t newcount, size_t size, size_t alignment);
760 void* mi_heap_recalloc_aligned_at(mi_heap_t* heap, void* p, size_t newcount, size_t size, size_t alignment, size_t offset);
761
763
772
784#define mi_malloc_tp(tp) ((tp*)mi_malloc(sizeof(tp)))
785
787#define mi_zalloc_tp(tp) ((tp*)mi_zalloc(sizeof(tp)))
788
790#define mi_calloc_tp(tp,count) ((tp*)mi_calloc(count,sizeof(tp)))
791
793#define mi_mallocn_tp(tp,count) ((tp*)mi_mallocn(count,sizeof(tp)))
794
796#define mi_reallocn_tp(p,tp,count) ((tp*)mi_reallocn(p,count,sizeof(tp)))
797
799#define mi_heap_malloc_tp(hp,tp) ((tp*)mi_heap_malloc(hp,sizeof(tp)))
800
802#define mi_heap_zalloc_tp(hp,tp) ((tp*)mi_heap_zalloc(hp,sizeof(tp)))
803
805#define mi_heap_calloc_tp(hp,tp,count) ((tp*)mi_heap_calloc(hp,count,sizeof(tp)))
806
808#define mi_heap_mallocn_tp(hp,tp,count) ((tp*)mi_heap_mallocn(hp,count,sizeof(tp)))
809
811#define mi_heap_reallocn_tp(hp,p,tp,count) ((tp*)mi_heap_reallocn(p,count,sizeof(tp)))
812
814#define mi_heap_recalloc_tp(hp,p,tp,count) ((tp*)mi_heap_recalloc(p,count,sizeof(tp)))
815
817
823
830 bool mi_heap_contains_block(mi_heap_t* heap, const void* p);
831
840 bool mi_heap_check_owned(mi_heap_t* heap, const void* p);
841
849 bool mi_check_owned(const void* p);
850
853 typedef struct mi_heap_area_s {
854 void* blocks;
855 size_t reserved;
856 size_t committed;
857 size_t used;
858 size_t block_size;
859 size_t full_block_size;
860 int heap_tag;
861} mi_heap_area_t;
862
870 typedef bool (mi_block_visit_fun)(const mi_heap_t* heap, const mi_heap_area_t* area, void* block, size_t block_size, void* arg);
871
883 bool mi_heap_visit_blocks(const mi_heap_t* heap, bool visit_all_blocks, mi_block_visit_fun* visitor, void* arg);
884
900 bool mi_abandoned_visit_blocks(mi_subproc_id_t subproc_id, int heap_tag, bool visit_blocks, mi_block_visit_fun* visitor, void* arg);
901
903
909
911 typedef enum mi_option_e {
912 // stable options
913 mi_option_show_errors,
914 mi_option_show_stats,
915 mi_option_verbose,
916 mi_option_max_errors,
917 mi_option_max_warnings,
918
919 // advanced options
920 mi_option_reserve_huge_os_pages,
921 mi_option_reserve_huge_os_pages_at,
922 mi_option_reserve_os_memory,
923 mi_option_allow_large_os_pages,
924 mi_option_purge_decommits,
925 mi_option_arena_reserve,
926 mi_option_os_tag,
927 mi_option_retry_on_oom,
928
929 // experimental options
930 mi_option_eager_commit,
931 mi_option_eager_commit_delay,
932 mi_option_arena_eager_commit,
933 mi_option_abandoned_page_purge,
934 mi_option_purge_delay,
935 mi_option_use_numa_nodes,
936 mi_option_disallow_os_alloc,
937 mi_option_limit_os_alloc,
938 mi_option_max_segment_reclaim,
939 mi_option_destroy_on_exit,
940 mi_option_arena_purge_mult,
941 mi_option_abandoned_reclaim_on_free,
942 mi_option_purge_extend_delay,
943 mi_option_disallow_arena_alloc,
944 mi_option_visit_abandoned,
945
946 _mi_option_last
947} mi_option_t;
948
949
950 bool mi_option_is_enabled(mi_option_t option);
951 void mi_option_enable(mi_option_t option);
952 void mi_option_disable(mi_option_t option);
953 void mi_option_set_enabled(mi_option_t option, bool enable);
954 void mi_option_set_enabled_default(mi_option_t option, bool enable);
955
956 long mi_option_get(mi_option_t option);
957 long mi_option_get_clamp(mi_option_t option, long min, long max);
958 size_t mi_option_get_size(mi_option_t option);
959
960 void mi_option_set(mi_option_t option, long value);
961 void mi_option_set_default(mi_option_t option, long value);
962
963
965
972
974 void mi_cfree(void* p);
975 void* mi__expand(void* p, size_t newsize);
976
977void* mi_recalloc(void* p, size_t count, size_t size);
978 size_t mi_malloc_size(const void* p);
979 size_t mi_malloc_good_size(size_t size);
980 size_t mi_malloc_usable_size(const void *p);
981
982 int mi_posix_memalign(void** p, size_t alignment, size_t size);
983 int mi__posix_memalign(void** p, size_t alignment, size_t size);
984 void* mi_memalign(size_t alignment, size_t size);
985 void* mi_valloc(size_t size);
986 void* mi_pvalloc(size_t size);
987 void* mi_aligned_alloc(size_t alignment, size_t size);
988
989 unsigned short* mi_wcsdup(const unsigned short* s);
990 unsigned char* mi_mbsdup(const unsigned char* s);
991 int mi_dupenv_s(char** buf, size_t* size, const char* name);
992 int mi_wdupenv_s(unsigned short** buf, size_t* size, const unsigned short* name);
993
996 void* mi_reallocarray(void* p, size_t count, size_t size);
997
999 int mi_reallocarr(void* p, size_t count, size_t size);
1000
1001 void* mi_aligned_recalloc(void* p, size_t newcount, size_t size, size_t alignment);
1002 void* mi_aligned_offset_recalloc(void* p, size_t newcount, size_t size, size_t alignment, size_t offset);
1003
1004 void mi_free_size(void* p, size_t size);
1005 void mi_free_size_aligned(void* p, size_t size, size_t alignment);
1006 void mi_free_aligned(void* p, size_t alignment);
1007
1009
1022
1024 void* mi_new(std::size_t n) noexcept(false);
1025
1027 void* mi_new_n(size_t count, size_t size) noexcept(false);
1028
1030 void* mi_new_aligned(std::size_t n, std::align_val_t alignment) noexcept(false);
1031
1033 void* mi_new_nothrow(size_t n);
1034
1036 void* mi_new_aligned_nothrow(size_t n, size_t alignment);
1037
1039 void* mi_new_realloc(void* p, size_t newsize);
1040
1042 void* mi_new_reallocn(void* p, size_t newcount, size_t size);
1043
1051 template<class T> struct mi_stl_allocator { }
1052
1054
1113
1198
1263
1433
mi_malloc_aligned_at
void * mi_malloc_aligned_at(size_t size, size_t alignment, size_t offset)
Allocate size bytes aligned by alignment at a specified offset.
mi_calloc_aligned
void * mi_calloc_aligned(size_t count, size_t size, size_t alignment)
mi_realloc_aligned
void * mi_realloc_aligned(void *p, size_t newsize, size_t alignment)
mi_malloc_aligned
void * mi_malloc_aligned(size_t size, size_t alignment)
Allocate size bytes aligned by alignment.
mi_zalloc_aligned_at
void * mi_zalloc_aligned_at(size_t size, size_t alignment, size_t offset)
mi_calloc_aligned_at
void * mi_calloc_aligned_at(size_t count, size_t size, size_t alignment, size_t offset)
mi_zalloc_aligned
void * mi_zalloc_aligned(size_t size, size_t alignment)
mi_realloc_aligned_at
void * mi_realloc_aligned_at(void *p, size_t newsize, size_t alignment, size_t offset)
mi_heap_area_t::heap_tag
int heap_tag
heap tag associated with this area (see mi_heap_new_ex)
Definition mimalloc-doc.h:860
mi_heap_area_t::block_size
size_t block_size
size in bytes of one block
Definition mimalloc-doc.h:858
mi_heap_area_t::committed
size_t committed
current committed bytes of this area
Definition mimalloc-doc.h:856
mi_heap_area_t::full_block_size
size_t full_block_size
size in bytes of a full block including padding and metadata.
Definition mimalloc-doc.h:859
mi_heap_area_t::used
size_t used
bytes in use by allocated blocks
Definition mimalloc-doc.h:857
mi_heap_area_t::blocks
void * blocks
start of the area containing heap blocks
Definition mimalloc-doc.h:854
mi_heap_area_t::reserved
size_t reserved
bytes reserved for this area
Definition mimalloc-doc.h:855
mi_heap_check_owned
bool mi_heap_check_owned(mi_heap_t *heap, const void *p)
Check safely if any pointer is part of a heap.
mi_check_owned
bool mi_check_owned(const void *p)
Check safely if any pointer is part of the default heap of this thread.
mi_abandoned_visit_blocks
bool mi_abandoned_visit_blocks(mi_subproc_id_t subproc_id, int heap_tag, bool visit_blocks, mi_block_visit_fun *visitor, void *arg)
Visit all areas and blocks in abandoned heaps.
mi_heap_visit_blocks
bool mi_heap_visit_blocks(const mi_heap_t *heap, bool visit_all_blocks, mi_block_visit_fun *visitor, void *arg)
Visit all areas and blocks in a heap.
mi_block_visit_fun
bool mi_block_visit_fun(const mi_heap_t *heap, const mi_heap_area_t *area, void *block, size_t block_size, void *arg)
Visitor function passed to mi_heap_visit_blocks()
Definition mimalloc-doc.h:870
mi_heap_contains_block
bool mi_heap_contains_block(mi_heap_t *heap, const void *p)
Does a heap contain a pointer to a previously allocated block?
mi_heap_area_t
An area of heap space contains blocks of a single size.
Definition mimalloc-doc.h:853
mi_new_nothrow
void * mi_new_nothrow(size_t n)
like mi_malloc, but when out of memory, use std::get_new_handler but return NULL on failure.
mi_new
void * mi_new(std::size_t n) noexcept(false)
like mi_malloc(), but when out of memory, use std::get_new_handler and raise std::bad_alloc exception...
mi_new_realloc
void * mi_new_realloc(void *p, size_t newsize)
like mi_realloc(), but when out of memory, use std::get_new_handler and raise std::bad_alloc exceptio...
mi_new_aligned
void * mi_new_aligned(std::size_t n, std::align_val_t alignment) noexcept(false)
like mi_malloc_aligned(), but when out of memory, use std::get_new_handler and raise std::bad_alloc e...
mi_new_aligned_nothrow
void * mi_new_aligned_nothrow(size_t n, size_t alignment)
like mi_malloc_aligned, but when out of memory, use std::get_new_handler but return NULL on failure.
mi_new_reallocn
void * mi_new_reallocn(void *p, size_t newcount, size_t size)
like mi_reallocn(), but when out of memory, use std::get_new_handler and raise std::bad_alloc excepti...
mi_new_n
void * mi_new_n(size_t count, size_t size) noexcept(false)
like mi_mallocn(), but when out of memory, use std::get_new_handler and raise std::bad_alloc exceptio...
mi_stl_allocator
std::allocator implementation for mimalloc for use in STL containers.
Definition mimalloc-doc.h:1051
mi_reserve_os_memory
int mi_reserve_os_memory(size_t size, bool commit, bool allow_large)
Reserve OS memory for use by mimalloc.
mi_usable_size
size_t mi_usable_size(void *p)
Return the available bytes in a memory block.
mi_thread_done
void mi_thread_done(void)
Uninitialize mimalloc on a thread.
mi_deferred_free_fun
void mi_deferred_free_fun(bool force, unsigned long long heartbeat, void *arg)
Type of deferred free functions.
Definition mimalloc-doc.h:354
mi_stats_print
void mi_stats_print(void *out)
Deprecated.
mi_subproc_main
mi_subproc_id_t mi_subproc_main(void)
Get the main sub-process identifier.
mi_reserve_huge_os_pages_interleave
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 t...
mi_reserve_os_memory_ex
int mi_reserve_os_memory_ex(size_t size, bool commit, bool allow_large, bool exclusive, mi_arena_id_t *arena_id)
Reserve OS memory to be managed in an arena.
mi_register_deferred_free
void mi_register_deferred_free(mi_deferred_free_fun *deferred_free, void *arg)
Register a deferred free function.
mi_heap_new_ex
mi_heap_t * mi_heap_new_ex(int heap_tag, bool allow_destroy, mi_arena_id_t arena_id)
Create a new heap.
mi_stats_reset
void mi_stats_reset(void)
Reset statistics.
mi_manage_os_memory_ex
bool mi_manage_os_memory_ex(void *start, size_t size, bool is_committed, bool is_large, bool is_zero, int numa_node, bool exclusive, mi_arena_id_t *arena_id)
Manage externally allocated memory as a mimalloc arena.
mi_collect
void mi_collect(bool force)
Eagerly free memory.
mi_manage_os_memory
bool mi_manage_os_memory(void *start, size_t size, bool is_committed, bool is_large, bool is_zero, int numa_node)
Manage a particular memory area for use by mimalloc.
mi_zalloc_small
void * mi_zalloc_small(size_t size)
Allocate a zero initialized small object.
mi_stats_print_out
void mi_stats_print_out(mi_output_fun *out, void *arg)
Print the main statistics.
mi_reserve_huge_os_pages_at_ex
int mi_reserve_huge_os_pages_at_ex(size_t pages, int numa_node, size_t timeout_msecs, bool exclusive, mi_arena_id_t *arena_id)
Reserve huge OS pages (1GiB) into a single arena.
mi_is_in_heap_region
bool mi_is_in_heap_region(const void *p)
Is a pointer part of our heap?
mi_reserve_huge_os_pages_at
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 ...
mi_process_info
void mi_process_info(size_t *elapsed_msecs, size_t *user_msecs, size_t *system_msecs, size_t *current_rss, size_t *peak_rss, size_t *current_commit, size_t *peak_commit, size_t *page_faults)
Return process information (time and memory usage).
mi_malloc_small
void * mi_malloc_small(size_t size)
Allocate a small object.
mi_subproc_new
mi_subproc_id_t mi_subproc_new(void)
Create a fresh sub-process (with no associated threads yet).
mi_error_fun
void mi_error_fun(int err, void *arg)
Type of error callback functions.
Definition mimalloc-doc.h:393
mi_stats_merge
void mi_stats_merge(void)
Merge thread local statistics with the main statistics and reset.
mi_subproc_id_t
void * mi_subproc_id_t
A process can associate threads with sub-processes.
Definition mimalloc-doc.h:557
mi_arena_id_t
int mi_arena_id_t
Mimalloc uses large (virtual) memory areas, called "arena"s, from the OS to manage its memory.
Definition mimalloc-doc.h:499
mi_arena_area
void * mi_arena_area(mi_arena_id_t arena_id, size_t *size)
Return the size of an arena.
mi_register_error
void mi_register_error(mi_error_fun *errfun, void *arg)
Register an error callback function.
mi_subproc_delete
void mi_subproc_delete(mi_subproc_id_t subproc)
Delete a previously created sub-process.
mi_is_redirected
bool mi_is_redirected()
Is the C runtime malloc API redirected?
mi_heap_new_in_arena
mi_heap_t * mi_heap_new_in_arena(mi_arena_id_t arena_id)
Create a new heap that only allocates in the specified arena.
mi_thread_stats_print_out
void mi_thread_stats_print_out(mi_output_fun *out, void *arg)
Print out heap statistics for this thread.
mi_good_size
size_t mi_good_size(size_t size)
Return the used allocation size.
mi_debug_show_arenas
void mi_debug_show_arenas(bool show_inuse, bool show_abandoned, bool show_purge)
Show all current arena's.
mi_subproc_add_current_thread
void mi_subproc_add_current_thread(mi_subproc_id_t subproc)
Add the current thread to the given sub-process.
mi_output_fun
void mi_output_fun(const char *msg, void *arg)
Type of output functions.
Definition mimalloc-doc.h:378
mi_register_output
void mi_register_output(mi_output_fun *out, void *arg)
Register an output function.
mi_thread_init
void mi_thread_init(void)
Initialize mimalloc on a thread.
mi_heap_malloc_small
void * mi_heap_malloc_small(mi_heap_t *heap, size_t size)
Allocate a small object in a specific heap.
mi_heap_get_default
mi_heap_t * mi_heap_get_default()
Get the default heap that is used for mi_malloc() et al.
mi_heap_delete
void mi_heap_delete(mi_heap_t *heap)
Delete a previously allocated heap.
mi_heap_malloc_aligned
void * mi_heap_malloc_aligned(mi_heap_t *heap, size_t size, size_t alignment)
mi_heap_set_default
mi_heap_t * mi_heap_set_default(mi_heap_t *heap)
Set the default heap to use in the current thread for mi_malloc() et al.
mi_heap_t
struct mi_heap_s mi_heap_t
Type of first-class heaps.
Definition mimalloc-doc.h:646
mi_heap_zalloc_aligned_at
void * mi_heap_zalloc_aligned_at(mi_heap_t *heap, size_t size, size_t alignment, size_t offset)
mi_heap_realpath
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.
mi_heap_strdup
char * mi_heap_strdup(mi_heap_t *heap, const char *s)
Duplicate a string in a specific heap.
mi_heap_zalloc_aligned
void * mi_heap_zalloc_aligned(mi_heap_t *heap, size_t size, size_t alignment)
mi_heap_realloc_aligned_at
void * mi_heap_realloc_aligned_at(mi_heap_t *heap, void *p, size_t newsize, size_t alignment, size_t offset)
mi_heap_collect
void mi_heap_collect(mi_heap_t *heap, bool force)
Release outstanding resources in a specific heap.
mi_heap_destroy
void mi_heap_destroy(mi_heap_t *heap)
Destroy a heap, freeing all its still allocated blocks.
mi_heap_calloc_aligned_at
void * mi_heap_calloc_aligned_at(mi_heap_t *heap, size_t count, size_t size, size_t alignment, size_t offset)
mi_heap_new
mi_heap_t * mi_heap_new()
Create a new heap that can be used for allocation.
mi_heap_mallocn
void * mi_heap_mallocn(mi_heap_t *heap, size_t count, size_t size)
Allocate count elements in a specific heap.
mi_heap_malloc
void * mi_heap_malloc(mi_heap_t *heap, size_t size)
Allocate in a specific heap.
mi_heap_zalloc
void * mi_heap_zalloc(mi_heap_t *heap, size_t size)
Allocate zero-initialized in a specific heap.
mi_heap_calloc
void * mi_heap_calloc(mi_heap_t *heap, size_t count, size_t size)
Allocate count zero-initialized elements in a specific heap.
mi_heap_realloc
void * mi_heap_realloc(mi_heap_t *heap, void *p, size_t newsize)
mi_heap_get_backing
mi_heap_t * mi_heap_get_backing()
Get the backing heap.
mi_heap_calloc_aligned
void * mi_heap_calloc_aligned(mi_heap_t *heap, size_t count, size_t size, size_t alignment)
mi_heap_reallocn
void * mi_heap_reallocn(mi_heap_t *heap, void *p, size_t count, size_t size)
mi_heap_realloc_aligned
void * mi_heap_realloc_aligned(mi_heap_t *heap, void *p, size_t newsize, size_t alignment)
mi_heap_strndup
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.
mi_heap_reallocf
void * mi_heap_reallocf(mi_heap_t *heap, void *p, size_t newsize)
mi_heap_malloc_aligned_at
void * mi_heap_malloc_aligned_at(mi_heap_t *heap, size_t size, size_t alignment, size_t offset)
mi_realloc
void * mi_realloc(void *p, size_t newsize)
Re-allocate memory to newsize bytes.
mi_expand
void * mi_expand(void *p, size_t newsize)
Try to re-allocate memory to newsize bytes in place.
mi_recalloc
void * mi_recalloc(void *p, size_t count, size_t size)
Re-allocate memory to count elements of size bytes, with extra memory initialized to zero.
mi_strdup
char * mi_strdup(const char *s)
Allocate and duplicate a string.
mi_strndup
char * mi_strndup(const char *s, size_t n)
Allocate and duplicate a string up to n bytes.
mi_reallocf
void * mi_reallocf(void *p, size_t newsize)
Re-allocate memory to newsize bytes,.
mi_mallocn
void * mi_mallocn(size_t count, size_t size)
Allocate count elements of size bytes.
mi_calloc
void * mi_calloc(size_t count, size_t size)
Allocate zero-initialized count elements of size bytes.
mi_reallocn
void * mi_reallocn(void *p, size_t count, size_t size)
Re-allocate memory to count elements of size bytes.
mi_realpath
char * mi_realpath(const char *fname, char *resolved_name)
Resolve a file path name.
mi_malloc
void * mi_malloc(size_t size)
Allocate size bytes.
mi_zalloc
void * mi_zalloc(size_t size)
Allocate zero-initialized size bytes.
mi_free
void mi_free(void *p)
Free previously allocated memory.
mi_option_enable
void mi_option_enable(mi_option_t option)
mi_option_get_size
size_t mi_option_get_size(mi_option_t option)
mi_option_is_enabled
bool mi_option_is_enabled(mi_option_t option)
mi_option_set_enabled_default
void mi_option_set_enabled_default(mi_option_t option, bool enable)
mi_option_get
long mi_option_get(mi_option_t option)
mi_option_set_default
void mi_option_set_default(mi_option_t option, long value)
mi_option_get_clamp
long mi_option_get_clamp(mi_option_t option, long min, long max)
mi_option_set_enabled
void mi_option_set_enabled(mi_option_t option, bool enable)
mi_option_disable
void mi_option_disable(mi_option_t option)
mi_option_set
void mi_option_set(mi_option_t option, long value)
mi_option_t
mi_option_t
Runtime options.
Definition mimalloc-doc.h:911
mi_option_abandoned_reclaim_on_free
@ mi_option_abandoned_reclaim_on_free
allow to reclaim an abandoned segment on a free (=1)
Definition mimalloc-doc.h:941
mi_option_purge_extend_delay
@ mi_option_purge_extend_delay
extend purge delay on each subsequent delay (=1)
Definition mimalloc-doc.h:942
mi_option_show_stats
@ mi_option_show_stats
Print statistics on termination.
Definition mimalloc-doc.h:914
mi_option_use_numa_nodes
@ mi_option_use_numa_nodes
0 = use all available numa nodes, otherwise use at most N nodes.
Definition mimalloc-doc.h:935
mi_option_abandoned_page_purge
@ mi_option_abandoned_page_purge
immediately purge delayed purges on thread termination
Definition mimalloc-doc.h:933
mi_option_eager_commit_delay
@ mi_option_eager_commit_delay
the first N segments per thread are not eagerly committed (but per page in the segment on demand)
Definition mimalloc-doc.h:931
mi_option_eager_commit
@ mi_option_eager_commit
eager commit segments? (after eager_commit_delay segments) (enabled by default).
Definition mimalloc-doc.h:930
mi_option_visit_abandoned
@ mi_option_visit_abandoned
allow visiting heap blocks from abandoned threads (=0)
Definition mimalloc-doc.h:944
mi_option_os_tag
@ mi_option_os_tag
tag used for OS logging (macOS only for now) (=100)
Definition mimalloc-doc.h:926
_mi_option_last
@ _mi_option_last
Definition mimalloc-doc.h:946
mi_option_destroy_on_exit
@ mi_option_destroy_on_exit
if set, release all memory on exit; sometimes used for dynamic unloading but can be unsafe
Definition mimalloc-doc.h:939
mi_option_verbose
@ mi_option_verbose
Print verbose messages.
Definition mimalloc-doc.h:915
mi_option_allow_large_os_pages
@ mi_option_allow_large_os_pages
allow large (2 or 4 MiB) OS pages, implies eager commit. If false, also disables THP for the process.
Definition mimalloc-doc.h:923
mi_option_arena_purge_mult
@ mi_option_arena_purge_mult
multiplier for purge_delay for the purging delay for arenas (=10)
Definition mimalloc-doc.h:940
mi_option_retry_on_oom
@ mi_option_retry_on_oom
retry on out-of-memory for N milli seconds (=400), set to 0 to disable retries. (only on windows)
Definition mimalloc-doc.h:927
mi_option_purge_decommits
@ mi_option_purge_decommits
should a memory purge decommit? (=1). Set to 0 to use memory reset on a purge (instead of decommit)
Definition mimalloc-doc.h:924
mi_option_limit_os_alloc
@ mi_option_limit_os_alloc
If set to 1, do not use OS memory for allocation (but only pre-reserved arenas)
Definition mimalloc-doc.h:937
mi_option_reserve_huge_os_pages_at
@ mi_option_reserve_huge_os_pages_at
Reserve N huge OS pages at a specific NUMA node N.
Definition mimalloc-doc.h:921
mi_option_max_segment_reclaim
@ mi_option_max_segment_reclaim
max. percentage of the abandoned segments can be reclaimed per try (=10%)
Definition mimalloc-doc.h:938
mi_option_arena_reserve
@ mi_option_arena_reserve
initial memory size for arena reservation (= 1 GiB on 64-bit) (internally, this value is in KiB; use ...
Definition mimalloc-doc.h:925
mi_option_reserve_huge_os_pages
@ mi_option_reserve_huge_os_pages
reserve N huge OS pages (1GiB pages) at startup
Definition mimalloc-doc.h:920
mi_option_disallow_os_alloc
@ mi_option_disallow_os_alloc
1 = do not use OS memory for allocation (but only programmatically reserved arenas)
Definition mimalloc-doc.h:936
mi_option_purge_delay
@ mi_option_purge_delay
memory purging is delayed by N milli seconds; use 0 for immediate purging or -1 for no purging at all...
Definition mimalloc-doc.h:934
mi_option_disallow_arena_alloc
@ mi_option_disallow_arena_alloc
1 = do not use arena's for allocation (except if using specific arena id's)
Definition mimalloc-doc.h:943
mi_option_max_errors
@ mi_option_max_errors
issue at most N error messages
Definition mimalloc-doc.h:916
mi_option_max_warnings
@ mi_option_max_warnings
issue at most N warning messages
Definition mimalloc-doc.h:917
mi_option_show_errors
@ mi_option_show_errors
Print error messages.
Definition mimalloc-doc.h:913
mi_option_reserve_os_memory
@ mi_option_reserve_os_memory
reserve specified amount of OS memory in an arena at startup (internally, this value is in KiB; use m...
Definition mimalloc-doc.h:922
mi_option_arena_eager_commit
@ mi_option_arena_eager_commit
eager commit arenas? Use 2 to enable just on overcommit systems (=2)
Definition mimalloc-doc.h:932
mi_malloc_usable_size
size_t mi_malloc_usable_size(const void *p)
mi_free_aligned
void mi_free_aligned(void *p, size_t alignment)
mi_aligned_offset_recalloc
void * mi_aligned_offset_recalloc(void *p, size_t newcount, size_t size, size_t alignment, size_t offset)
mi_aligned_alloc
void * mi_aligned_alloc(size_t alignment, size_t size)
mi_malloc_size
size_t mi_malloc_size(const void *p)
mi_valloc
void * mi_valloc(size_t size)
mi_pvalloc
void * mi_pvalloc(size_t size)
mi__expand
void * mi__expand(void *p, size_t newsize)
mi_wdupenv_s
int mi_wdupenv_s(unsigned short **buf, size_t *size, const unsigned short *name)
mi_cfree
void mi_cfree(void *p)
Just as free but also checks if the pointer p belongs to our heap.
mi_memalign
void * mi_memalign(size_t alignment, size_t size)
mi_free_size_aligned
void mi_free_size_aligned(void *p, size_t size, size_t alignment)
mi_mbsdup
unsigned char * mi_mbsdup(const unsigned char *s)
mi_reallocarr
int mi_reallocarr(void *p, size_t count, size_t size)
Corresponds to reallocarr in NetBSD.
mi_malloc_good_size
size_t mi_malloc_good_size(size_t size)
mi_wcsdup
unsigned short * mi_wcsdup(const unsigned short *s)
mi_dupenv_s
int mi_dupenv_s(char **buf, size_t *size, const char *name)
mi_posix_memalign
int mi_posix_memalign(void **p, size_t alignment, size_t size)
mi__posix_memalign
int mi__posix_memalign(void **p, size_t alignment, size_t size)
mi_reallocarray
void * mi_reallocarray(void *p, size_t count, size_t size)
Correspond s to reallocarray in FreeBSD.
mi_free_size
void mi_free_size(void *p, size_t size)
mi_aligned_recalloc
void * mi_aligned_recalloc(void *p, size_t newcount, size_t size, size_t alignment)
mi_heap_recalloc_aligned_at
void * mi_heap_recalloc_aligned_at(mi_heap_t *heap, void *p, size_t newcount, size_t size, size_t alignment, size_t offset)
mi_heap_rezalloc_aligned_at
void * mi_heap_rezalloc_aligned_at(mi_heap_t *heap, void *p, size_t newsize, size_t alignment, size_t offset)
mi_recalloc_aligned
void * mi_recalloc_aligned(void *p, size_t newcount, size_t size, size_t alignment)
mi_rezalloc_aligned
void * mi_rezalloc_aligned(void *p, size_t newsize, size_t alignment)
mi_heap_rezalloc_aligned
void * mi_heap_rezalloc_aligned(mi_heap_t *heap, void *p, size_t newsize, size_t alignment)
mi_rezalloc_aligned_at
void * mi_rezalloc_aligned_at(void *p, size_t newsize, size_t alignment, size_t offset)
mi_heap_recalloc_aligned
void * mi_heap_recalloc_aligned(mi_heap_t *heap, void *p, size_t newcount, size_t size, size_t alignment)
mi_heap_rezalloc
void * mi_heap_rezalloc(mi_heap_t *heap, void *p, size_t newsize)
mi_recalloc_aligned_at
void * mi_recalloc_aligned_at(void *p, size_t newcount, size_t size, size_t alignment, size_t offset)
mi_heap_recalloc
void * mi_heap_recalloc(mi_heap_t *heap, void *p, size_t newcount, size_t size)
mi_rezalloc
void * mi_rezalloc(void *p, size_t newsize)