mi-malloc 3.7/2.5/1.15
Loading...
Searching...
No Matches
mimalloc-doc.h
1/* ----------------------------------------------------------------------------
2Copyright (c) 2018-2026, 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
132
133
137
138
145void mi_free(void* p);
146
151void mi_cfree(void* p);
152
157void* mi_malloc(size_t size);
158
163void* mi_zalloc(size_t size);
164
174void* mi_calloc(size_t count, size_t size);
175
189void* mi_realloc(void* p, size_t newsize);
190
204void* mi_expand(void* p, size_t newsize);
205
215void* mi_mallocn(size_t count, size_t size);
216
226void* mi_reallocn(void* p, size_t count, size_t size);
227
244void* mi_reallocf(void* p, size_t newsize);
245
246
255char* mi_strdup(const char* s);
256
266char* mi_strndup(const char* s, size_t n);
267
280char* mi_realpath(const char* fname, char* resolved_name);
281
296size_t mi_usable_size(void* p);
297
308size_t mi_allocated_size(const void* p);
309
320size_t mi_thread_id_of(const void* p);
321
335size_t mi_good_size(size_t size);
336
338
339// ------------------------------------------------------
340// Aligned allocation
341// ------------------------------------------------------
342
355
373void* mi_malloc_aligned(size_t size, size_t alignment);
374void* mi_zalloc_aligned(size_t size, size_t alignment);
375void* mi_calloc_aligned(size_t count, size_t size, size_t alignment);
376void* mi_realloc_aligned(void* p, size_t newsize, size_t alignment);
377
389void* mi_malloc_aligned_at(size_t size, size_t alignment, size_t offset);
390void* mi_zalloc_aligned_at(size_t size, size_t alignment, size_t offset);
391void* mi_calloc_aligned_at(size_t count, size_t size, size_t alignment, size_t offset);
392void* mi_realloc_aligned_at(void* p, size_t newsize, size_t alignment, size_t offset);
393
395
396
406
420#define mi_malloc_tp(tp) ((tp*)mi_malloc_csize(sizeof(tp)))
421
428#define mi_free_tp(tp,p) (mi_free_csize(p,sizeof(tp)))
429
431#define mi_zalloc_tp(tp) ((tp*)mi_zalloc_csize(sizeof(tp)))
432
434#define mi_calloc_tp(tp,count) ((tp*)mi_calloc(count,sizeof(tp)))
435
437#define mi_mallocn_tp(tp,count) ((tp*)mi_mallocn(count,sizeof(tp)))
438
440#define mi_reallocn_tp(p,tp,count) ((tp*)mi_reallocn(p,count,sizeof(tp)))
441
443#define mi_recalloc_tp(tp,p,oldcount,newcount) ((tp*)mi_recalloc(p,oldcount,newcount,sizeof(tp)))
444
446#define mi_heap_malloc_tp(tp,hp) ((tp*)mi_heap_malloc(hp,sizeof(tp)))
447
449#define mi_heap_zalloc_tp(tp,hp) ((tp*)mi_heap_zalloc(hp,sizeof(tp)))
450
452#define mi_heap_calloc_tp(tp,hp,count) ((tp*)mi_heap_calloc(hp,count,sizeof(tp)))
453
455#define mi_heap_mallocn_tp(tp,hp,count) ((tp*)mi_heap_mallocn(hp,count,sizeof(tp)))
456
458#define mi_heap_reallocn_tp(tp,hp,p,count) ((tp*)mi_heap_reallocn(p,count,sizeof(tp)))
459
461#define mi_heap_recalloc_tp(tp,hp,p,oldcount,newcount) ((tp*)mi_heap_recalloc(hp,p,oldcount,newcount,sizeof(tp)))
462
464
478
484void* mi_malloc_csize(size_t size);
485
486void* mi_zalloc_csize(size_t size);
487
488void* mi_theap_malloc_csize(mi_theap_t* theap, size_t size);
489
490void* mi_theap_zalloc_csize(mi_theap_t* theap, size_t size);
491
497void mi_free_csize(void* p, size_t size);
498
504void mi_free_csize_nonnull(void* p, size_t size);
505
509void mi_free_csize_aligned(void* p, size_t size, size_t aligned);
510
512void mi_free_csize_aligned_nonnull(void* p, size_t size, size_t aligned);
513
515
521
524#define MI_SMALL_WSIZE_MAX 128
525
529#define MI_SMALL_SIZE_MAX (MI_SMALL_WSIZE_MAX*sizeof(size_t))
530
538void* mi_malloc_small(size_t size);
539
550void* mi_wmalloc_small(size_t wsize);
551
554void* mi_wzalloc_small(size_t wsize);
555
558size_t mi_wsize_from_size(size_t size);
559
567void* mi_zalloc_small(size_t size);
568
584void mi_free_small(void* p);
585
602
606
609
611
626
636void* mi_rezalloc(void* p, size_t oldsize, size_t newsize);
637
649void* mi_recalloc(void* p, size_t oldcount, size_t newcount, size_t size);
650
652void* mi_rezalloc_aligned(void* p, size_t oldsize, size_t newsize, size_t alignment);
653
655void* mi_rezalloc_aligned_at(void* p, size_t oldsize, size_t newsize, size_t alignment, size_t offset);
656
658void* mi_recalloc_aligned(void* p, size_t oldcount, size_t newcount, size_t size, size_t alignment);
659
661void* mi_recalloc_aligned_at(void* p, size_t oldcount, size_t newcount, size_t size, size_t alignment, size_t offset);
662
664void* mi_heap_rezalloc(mi_heap_t* heap, void* p, size_t oldsize, size_t newsize);
665
667void* mi_heap_recalloc(mi_heap_t* heap, void* p, size_t oldcount, size_t newcount, size_t size);
668
670void* mi_heap_rezalloc_aligned(mi_heap_t* heap, void* p, size_t oldsize, size_t newsize, size_t alignment);
671
673void* mi_heap_rezalloc_aligned_at(mi_heap_t* heap, void* p, size_t oldsize, size_t newsize, size_t alignment, size_t offset);
674
676void* mi_heap_recalloc_aligned(mi_heap_t* heap, void* p, size_t oldcount, size_t newcount, size_t size, size_t alignment);
677
679void* mi_heap_recalloc_aligned_at(mi_heap_t* heap, void* p, size_t oldcount, size_t newcount, size_t size, size_t alignment, size_t offset);
680
682
683
684
705
711struct mi_heap_s;
712
718typedef struct mi_heap_s mi_heap_t;
719
722
742
760
775
781
786
794
798void mi_heap_set_numa_affinity(mi_heap_t* heap, int numa_node);
799
802void mi_heap_set_debug_fill_preserve(mi_heap_t* heap, size_t preserve);
803
810
816mi_heap_t* mi_heap_of(const void* p);
817
822bool mi_heap_contains(const mi_heap_t* heap, const void* p);
823
827bool mi_any_heap_contains(const void* p);
828
829
835bool mi_is_in_heap_region(const void* p);
836
842bool mi_check_owned(const void* p);
843
850bool mi_heap_contains_block(mi_heap_t* heap, const void* p);
851
858bool mi_heap_check_owned(mi_heap_t* heap, const void* p);
859
861void mi_heap_collect(mi_heap_t* heap, bool force);
862
865void* mi_heap_malloc(mi_heap_t* heap, size_t size);
866
870void* mi_heap_malloc_small(mi_heap_t* heap, size_t size);
871
874void* mi_heap_zalloc(mi_heap_t* heap, size_t size);
875
879void* mi_heap_zalloc_small(mi_heap_t* heap, size_t size);
880
883void* mi_heap_calloc(mi_heap_t* heap, size_t count, size_t size);
884
887void* mi_heap_mallocn(mi_heap_t* heap, size_t count, size_t size);
888
891char* mi_heap_strdup(mi_heap_t* heap, const char* s);
892
895char* mi_heap_strndup(mi_heap_t* heap, const char* s, size_t n);
896
899char* mi_heap_realpath(mi_heap_t* heap, const char* fname, char* resolved_name);
900
901void* mi_heap_realloc(mi_heap_t* heap, void* p, size_t newsize);
902void* mi_heap_reallocn(mi_heap_t* heap, void* p, size_t count, size_t size);
903void* mi_heap_reallocf(mi_heap_t* heap, void* p, size_t newsize);
904
905void* mi_heap_malloc_aligned(mi_heap_t* heap, size_t size, size_t alignment);
906void* mi_heap_malloc_aligned_at(mi_heap_t* heap, size_t size, size_t alignment, size_t offset);
907void* mi_heap_zalloc_aligned(mi_heap_t* heap, size_t size, size_t alignment);
908void* mi_heap_zalloc_aligned_at(mi_heap_t* heap, size_t size, size_t alignment, size_t offset);
909void* mi_heap_calloc_aligned(mi_heap_t* heap, size_t count, size_t size, size_t alignment);
910void* mi_heap_calloc_aligned_at(mi_heap_t* heap, size_t count, size_t size, size_t alignment, size_t offset);
911void* mi_heap_realloc_aligned(mi_heap_t* heap, void* p, size_t newsize, size_t alignment);
912void* mi_heap_realloc_aligned_at(mi_heap_t* heap, void* p, size_t newsize, size_t alignment, size_t offset);
913
915
916
917
922
923
926typedef struct mi_heap_area_s {
927 void* blocks;
928 size_t reserved;
929 size_t committed;
930 size_t used;
931 size_t block_size;
935
943typedef bool (mi_block_visit_fun)(const mi_heap_t* heap, const mi_heap_area_t* area, void* block, size_t block_size, void* arg);
944
969bool mi_heap_visit_blocks(const mi_heap_t* heap, bool visit_blocks, mi_block_visit_fun* visitor, void* arg);
970
974bool mi_heap_visit_abandoned_blocks(mi_heap_t* heap, bool visit_blocks, mi_block_visit_fun* visitor, void* arg);
975
979bool mi_unsafe_heap_page_is_under_utilized(mi_heap_t* heap, void* p, size_t perc_threshold);
980
996bool mi_abandoned_visit_blocks(mi_subproc_id_t subproc_id, int heap_tag, bool visit_blocks, mi_block_visit_fun* visitor, void* arg);
997
999
1000// ------------------------------------------------------
1001// Arenas
1002// ------------------------------------------------------
1003
1011
1013typedef int mi_arena_id_t;
1014
1023int mi_reserve_os_memory(size_t size, bool commit, bool allow_large);
1024
1032int mi_reserve_os_memory_ex(size_t size, bool commit, bool allow_large, bool exclusive, mi_arena_id_t* arena_id);
1033
1046int mi_reserve_huge_os_pages_interleave(size_t pages, size_t numa_nodes, size_t timeout_msecs);
1047
1060int mi_reserve_huge_os_pages_at(size_t pages, int numa_node, size_t timeout_msecs);
1061
1066int mi_reserve_huge_os_pages(size_t pages, double max_secs, size_t* pages_reserved);
1067
1075int 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);
1076
1080
1084
1088
1100bool mi_manage_os_memory(void* start, size_t size, bool is_committed, bool is_large, bool is_zero, int numa_node);
1101
1112bool 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);
1113
1119typedef bool (mi_commit_fun_t)(bool commit, void* start, size_t size, bool* is_zero, void* user_arg);
1120
1126bool mi_manage_memory(void* start, size_t size, bool is_committed, bool is_pinned, bool is_zero, int numa_node, bool exclusive,
1127 mi_commit_fun_t* commit_fun, void* commit_fun_arg, mi_arena_id_t* arena_id);
1128
1129
1132
1135
1139
1144void* mi_arena_area(mi_arena_id_t arena_id, size_t* size);
1145
1148bool mi_arena_contains(mi_arena_id_t arena_id, const void* p);
1149
1154
1166mi_heap_t* mi_heap_new_ex(int heap_tag, bool allow_destroy, mi_arena_id_t arena_id);
1167
1169
1170
1179
1184typedef void* mi_subproc_id_t;
1185
1188
1191
1195
1200
1206
1211
1215typedef bool (mi_heap_visit_fun)(mi_heap_t* heap, void* arg);
1216
1224
1226
1227
1228// ------------------------------------------------------
1229// Extended functionality
1230// ------------------------------------------------------
1231
1236
1240int mi_version(void);
1241
1249void mi_collect(bool force);
1250
1253void mi_collect_reduce(size_t target_thread_owned);
1254
1257
1261
1268
1274
1279
1290
1297typedef void (mi_deferred_free_fun)(bool force, unsigned long long heartbeat, void* arg);
1298
1321void mi_register_deferred_free(mi_deferred_free_fun* deferred_free, void* arg);
1322
1328typedef void (mi_output_fun)(const char* msg, void* arg);
1329
1339void mi_register_output(mi_output_fun* out, void* arg);
1340
1346typedef void (mi_error_fun)(int err, void* arg);
1347
1372void mi_register_error(mi_error_fun* errfun, void* arg);
1373
1375
1376
1377
1378
1379
1380// ------------------------------------------------------
1381// Statistics
1382// ------------------------------------------------------
1383
1387
1389#define MI_STAT_VERSION 4
1390
1400#define mi_stats_t_decl(name)
1401
1405 size_t size;
1407 size_t version;
1408};
1409
1411typedef struct mi_stats_s mi_stats_t;
1412
1414void mi_stats_header_init(mi_stats_t* stats);
1415
1418void mi_stats_init(mi_stats_t* stats);
1419
1420
1424
1430
1447void 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);
1448
1449
1454void mi_stats_print(void* out);
1455
1461void mi_stats_print_out(mi_output_fun* out, void* arg);
1462
1466
1472bool mi_stats_get(mi_stats_t* stats);
1473
1479char* mi_stats_get_json(size_t buf_size, char* buf);
1480
1482size_t mi_stats_get_bin_size(size_t bin);
1483
1490bool mi_heap_stats_get(mi_heap_t* heap, mi_stats_t* stats);
1491
1498char* mi_heap_stats_get_json(mi_heap_t* heap, size_t buf_size, char* buf); // use mi_free to free the result if the input buf == NULL
1499
1505
1510
1517bool mi_subproc_stats_get(mi_subproc_id_t subproc_id, mi_stats_t* stats);
1518
1522bool mi_subproc_stats_get_exclusive(mi_subproc_id_t subproc_id, mi_stats_t* stats);
1523
1527bool mi_theap_stats_get(mi_theap_t* theap, mi_stats_t* stats);
1528
1532
1539char* mi_subproc_stats_get_json(mi_subproc_id_t subproc_id, size_t buf_size, char* buf); // use mi_free to free the result if the input buf == NULL
1540
1546
1547
1553
1560char* mi_stats_as_json( mi_stats_t* stats, size_t buf_size, char* buf);
1561
1565
1569
1571
1572// ------------------------------------------------------
1573// Heap Profiling
1574// ------------------------------------------------------
1575
1638
1640typedef struct mi_profiler_s mi_profiler_t;
1641
1653mi_profiler_t* mi_pprof_profiler_new(size_t initial_threshold, const char* base_file_name, size_t alloc_interval_size, size_t inuse_interval_size, size_t time_interval_secs);
1654
1660
1692
1699
1706
1711
1717
1723
1731
1737
1741
1745
1749
1754
1756
1757// ------------------------------------------------------
1758// Runtime Options
1759// ------------------------------------------------------
1760
1783
1787
1794
1795
1800typedef enum mi_option_e {
1801 // stable options
1807
1808 // advanced options
1819
1820 // guard pages
1826
1827 // experimental options
1843
1844 // v3 options
1855
1857} mi_option_t;
1858
1859
1863void mi_option_set_enabled(mi_option_t option, bool enable);
1865
1867long mi_option_get_clamp(mi_option_t option, long min, long max);
1869
1870void mi_option_set(mi_option_t option, long value);
1871void mi_option_set_default(mi_option_t option, long value);
1872
1874
1875// ------------------------------------------------------
1876// Build Options
1877// ------------------------------------------------------
1878
1948
1961
1963struct mi_theap_s;
1964
1966typedef struct mi_theap_s mi_theap_t;
1967
1980
1986
1988void mi_theap_collect(mi_theap_t* theap, bool force);
1989
1993
1998
2007
2011
2014void* mi_theap_malloc(mi_theap_t* theap, size_t size);
2015
2019void* mi_theap_malloc_small(mi_theap_t* theap, size_t size);
2020
2023void* mi_theap_wmalloc_small(mi_theap_t* theap, size_t wsize);
2024
2027void* mi_theap_wzalloc_small(mi_theap_t* theap, size_t wsize);
2028
2031void* mi_theap_zalloc(mi_theap_t* theap, size_t size);
2032
2036void* mi_theap_zalloc_small(mi_theap_t* theap, size_t size);
2037
2038void* mi_theap_calloc(mi_theap_t* theap, size_t count, size_t size);
2039void* mi_theap_malloc_aligned(mi_theap_t* theap, size_t size, size_t alignment);
2040void* mi_theap_realloc(mi_theap_t* theap, void* p, size_t newsize);
2041
2043void* mi_theap_zalloc_aligned(mi_theap_t* theap, size_t size, size_t alignment);
2044
2046void* mi_theap_rezalloc(mi_theap_t* theap, void* p, size_t oldsize, size_t newsize);
2047
2049void* mi_theap_realloc_aligned(mi_theap_t* theap, void* p, size_t newsize, size_t alignment);
2050
2052void* mi_theap_rezalloc_aligned(mi_theap_t* theap, void* p, size_t oldsize, size_t newsize, size_t alignment);
2053
2057void mi_theap_guarded_set_sample_rate(mi_theap_t* theap, size_t sample_rate, size_t seed);
2058
2061void mi_theap_guarded_set_size_bound(mi_theap_t* theap, size_t min, size_t max);
2062
2067bool mi_theap_visit_blocks(const mi_theap_t* theap, bool visit_blocks, mi_block_visit_fun* visitor, void* arg);
2068
2070
2071// ------------------------------------------------------
2072// Allocation with usable sizes
2073// ------------------------------------------------------
2074
2081
2085void* mi_umalloc(size_t size, size_t* pusable_size);
2086
2090void* mi_uzalloc(size_t size, size_t* pusable_size);
2091
2095void* mi_ucalloc(size_t count, size_t size, size_t* pusable_size);
2096
2101void* mi_urealloc(void* p, size_t newsize, size_t* pusable_size_pre, size_t* pusable_size_post);
2102
2105void mi_ufree(void* p, size_t* pusable_size);
2106
2108void* mi_umalloc_aligned(size_t size, size_t alignment, size_t* pusable_size);
2109
2111void* mi_uzalloc_aligned(size_t size, size_t alignment, size_t* pusable_size);
2112
2114void* mi_urealloc_aligned(void* p, size_t newsize, size_t alignment, size_t* pusable_size_pre, size_t* pusable_size_post);
2115
2118void* mi_umalloc_small(size_t size, size_t* pusable_size);
2119
2122void* mi_uzalloc_small(size_t size, size_t* pusable_size);
2123
2125
2131
2132void* mi__expand(void* p, size_t newsize);
2133
2134size_t mi_malloc_size(const void* p);
2135size_t mi_malloc_good_size(size_t size);
2136size_t mi_malloc_usable_size(const void *p);
2137
2138int mi_posix_memalign(void** p, size_t alignment, size_t size);
2139int mi__posix_memalign(void** p, size_t alignment, size_t size);
2140void* mi_memalign(size_t alignment, size_t size);
2141void* mi_valloc(size_t size);
2142void* mi_pvalloc(size_t size);
2143
2146void* mi_aligned_alloc(size_t alignment, size_t size);
2147
2150void mi_free_aligned_sized(void* p, size_t alignment, size_t size);
2151
2152unsigned short* mi_wcsdup(const unsigned short* s);
2153unsigned char* mi_mbsdup(const unsigned char* s);
2154int mi_dupenv_s(char** buf, size_t* size, const char* name);
2155int mi_wdupenv_s(unsigned short** buf, size_t* size, const unsigned short* name);
2156
2159void* mi_reallocarray(void* p, size_t count, size_t size);
2160
2162int mi_reallocarr(void* p, size_t count, size_t size);
2163
2164void* mi_aligned_recalloc(void* p, size_t newcount, size_t size, size_t alignment);
2165void* mi_aligned_offset_recalloc(void* p, size_t newcount, size_t size, size_t alignment, size_t offset);
2166
2178void mi_free_sized(void* p, size_t size);
2179
2185void mi_free_sized_aligned(void* p, size_t size, size_t alignment);
2186
2191void mi_free_aligned(void* p, size_t alignment);
2192
2194void mi_free_size(void* p, size_t size);
2195
2197void mi_free_size_aligned(void* p, size_t size, size_t alignment);
2198
2200
2213
2215void* mi_new(std::size_t n) noexcept(false);
2216
2218void* mi_new_n(size_t count, size_t size) noexcept(false);
2219
2221void* mi_new_aligned(std::size_t n, std::align_val_t alignment) noexcept(false);
2222
2224void* mi_new_nothrow(size_t n);
2225
2227void* mi_new_aligned_nothrow(size_t n, size_t alignment);
2228
2230void* mi_new_realloc(void* p, size_t newsize);
2231
2233void* mi_new_reallocn(void* p, size_t newcount, size_t size);
2234
2236void* mi_heap_alloc_new(mi_heap_t* heap, size_t size);
2237
2239void* mi_heap_alloc_new_n(mi_heap_t* heap, size_t count, size_t size);
2240
2242void* mi_theap_alloc_new(mi_theap_t* theap, size_t size);
2243
2245void* mi_theap_alloc_new_n(mi_theap_t* theap, size_t count, size_t size);
2246
2249void* mi_theap_alloc_new_nothrow(mi_theap_t* theap, size_t size);
2250
2258template<class T> struct mi_stl_allocator { }
2259
2261
2368
2484
2615
2796
3004
3046
3074
3160
3258
void * mi_malloc_aligned_at(size_t size, size_t alignment, size_t offset)
Allocate size bytes aligned by alignment at a specified offset.
void * mi_calloc_aligned(size_t count, size_t size, size_t alignment)
void * mi_realloc_aligned(void *p, size_t newsize, size_t alignment)
void * mi_malloc_aligned(size_t size, size_t alignment)
Allocate size bytes aligned by alignment.
void * mi_zalloc_aligned_at(size_t size, size_t alignment, size_t offset)
void * mi_calloc_aligned_at(size_t count, size_t size, size_t alignment, size_t offset)
void * mi_zalloc_aligned(size_t size, size_t alignment)
void * mi_realloc_aligned_at(void *p, size_t newsize, size_t alignment, size_t offset)
int heap_tag
heap tag associated with this area (see mi_heap_new_ex)
Definition mimalloc-doc.h:933
size_t block_size
size in bytes of one block
Definition mimalloc-doc.h:931
size_t committed
current committed bytes of this area
Definition mimalloc-doc.h:929
size_t full_block_size
size in bytes of a full block including padding and metadata.
Definition mimalloc-doc.h:932
size_t used
bytes in use by allocated blocks
Definition mimalloc-doc.h:930
void * blocks
start of the area containing heap blocks
Definition mimalloc-doc.h:927
size_t reserved
bytes reserved for this area
Definition mimalloc-doc.h:928
bool mi_unsafe_heap_page_is_under_utilized(mi_heap_t *heap, void *p, size_t perc_threshold)
v3, experimental: Test whether an eligible page containing p is at most perc_threshold percent utiliz...
bool mi_abandoned_visit_blocks(mi_subproc_id_t subproc_id, int heap_tag, bool visit_blocks, mi_block_visit_fun *visitor, void *arg)
v1,v2: Visit all areas and blocks in abandoned heaps.
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:943
bool mi_heap_visit_abandoned_blocks(mi_heap_t *heap, bool visit_blocks, mi_block_visit_fun *visitor, void *arg)
v3: Visit only abandoned pages of heap, optionally visiting their allocated blocks.
bool mi_heap_visit_blocks(const mi_heap_t *heap, bool visit_blocks, mi_block_visit_fun *visitor, void *arg)
Visit all areas and blocks in a heap.
An area of heap space contains blocks of a single size.
Definition mimalloc-doc.h:926
int mi_reserve_os_memory(size_t size, bool commit, bool allow_large)
Reserve OS memory for use by mimalloc.
bool mi_arena_contains(mi_arena_id_t arena_id, const void *p)
v3: Test whether p is inside the arena or one of its subarenas.
void mi_arenas_print(void)
v3: Print the current subprocess's arenas; equivalent to mi_debug_show_arenas().
int mi_reserve_huge_os_pages(size_t pages, double max_secs, size_t *pages_reserved)
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...
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_heap_t * mi_heap_new_ex(int heap_tag, bool allow_destroy, mi_arena_id_t arena_id)
v1,v2: Create a new heap.
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.
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.
size_t mi_arena_max_object_size(void)
v3: Return the current maximum object size allowed in an arena, in bytes.
void mi_arenas_purge(void)
v3: Try to purge unused memory in the main subprocess's arenas.
bool mi_manage_memory(void *start, size_t size, bool is_committed, bool is_pinned, bool is_zero, int numa_node, bool exclusive, mi_commit_fun_t *commit_fun, void *commit_fun_arg, mi_arena_id_t *arena_id)
v3, experimental: As mi_manage_os_memory_ex(), with a custom commit/decommit callback.
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.
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 ...
size_t mi_arena_min_size(void)
v3: Return the minimum arena size in bytes.
void mi_debug_show_arenas(void)
Show all current arena's.
int mi_arena_id_t
Each arena has an associated identifier.
Definition mimalloc-doc.h:1013
void * mi_arena_area(mi_arena_id_t arena_id, size_t *size)
Return the start and size of an arena.
size_t mi_arena_min_alignment(void)
Return the minimal alignment required for managed OS memory.
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.
bool mi_commit_fun_t(bool commit, void *start, size_t size, bool *is_zero, void *user_arg)
experimental: Callback for committing or decommitting a managed memory range.
Definition mimalloc-doc.h:1119
void * mi_theap_malloc_csize(mi_theap_t *theap, size_t size)
void * mi_theap_zalloc_csize(mi_theap_t *theap, size_t size)
void mi_free_csize_nonnull(void *p, size_t size)
v3: Free a non-null pointer with a known constant size.
void mi_free_csize_aligned(void *p, size_t size, size_t aligned)
v3: Free a pointer using its known allocation size and alignment.
void mi_free_csize(void *p, size_t size)
v3: Free a pointer with a known constant size.
void * mi_malloc_csize(size_t size)
v3: Allocate a constant size object.
void * mi_zalloc_csize(size_t size)
void mi_free_csize_aligned_nonnull(void *p, size_t size, size_t aligned)
As mi_free_csize_aligned(), but p must not be NULL.
void * mi_theap_alloc_new(mi_theap_t *theap, size_t size)
As mi_new(), using a theap belonging to the calling thread.
void * mi_theap_alloc_new_nothrow(mi_theap_t *theap, size_t size)
As mi_new_nothrow(), using a theap belonging to the calling thread.
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.
void * mi_heap_alloc_new_n(mi_heap_t *heap, size_t count, size_t size)
As mi_new_n(), allocating count elements of size bytes from the specified heap.
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...
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...
void * mi_heap_alloc_new(mi_heap_t *heap, size_t size)
As mi_new(), allocating from the specified heap.
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...
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.
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...
void * mi_theap_alloc_new_n(mi_theap_t *theap, size_t count, size_t size)
As mi_new_n(), using a theap belonging to the calling thread.
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...
std::allocator implementation for mimalloc for use in STL containers.
Definition mimalloc-doc.h:2258
void mi_thread_done(void)
Uninitialize mimalloc on a thread.
void mi_collect_reduce(size_t target_thread_owned)
void mi_deferred_free_fun(bool force, unsigned long long heartbeat, void *arg)
Type of deferred free functions.
Definition mimalloc-doc.h:1297
void mi_process_init(void)
Initialize mimalloc for the process. Normally called automatically; repeated calls have no effect.
void mi_register_deferred_free(mi_deferred_free_fun *deferred_free, void *arg)
Register a deferred free function.
void mi_collect(bool force)
Eagerly free memory.
void mi_process_done(void)
Perform process-exit cleanup.
void mi_error_fun(int err, void *arg)
Type of error callback functions.
Definition mimalloc-doc.h:1346
void mi_register_error(mi_error_fun *errfun, void *arg)
Register an error callback function.
bool mi_is_redirected()
Is the C runtime malloc API redirected?
void mi_thread_set_in_threadpool(void)
v3: Communicate that a thread is in a threadpool.
void mi_output_fun(const char *msg, void *arg)
Type of output functions.
Definition mimalloc-doc.h:1328
void mi_register_output(mi_output_fun *out, void *arg)
Register an output function.
int mi_version(void)
Return the mimalloc version.
void mi_thread_init(void)
Initialize mimalloc on a thread.
void * mi_heap_malloc_small(mi_heap_t *heap, size_t size)
Allocate a small object in a specific heap.
void * mi_heap_zalloc_small(mi_heap_t *heap, size_t size)
Allocate a small object in a specific heap.
bool mi_heap_check_owned(mi_heap_t *heap, const void *p)
v1,v2: Check safely if any pointer is part of a heap.
mi_heap_t * mi_heap_get_default()
v1,v2: Get the default heap that is used for mi_malloc() et al.
bool mi_any_heap_contains(const void *p)
v3: is a pointer pointing into mimalloc managed memory?
void mi_heap_delete(mi_heap_t *heap)
Delete a heap, releasing its internal resources but keeping live blocks intact.
void mi_heap_set_debug_fill_preserve(mi_heap_t *heap, size_t preserve)
v3: Exclude the first preserve bytes of each block from debug filling on allocation and free.
void * mi_heap_malloc_aligned(mi_heap_t *heap, size_t size, size_t alignment)
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.
struct mi_heap_s mi_heap_t
Type of first-class heaps.
Definition mimalloc-doc.h:718
mi_heap_t * mi_heap_of(const void *p)
v3: return the heap that contains the given pointer.
void * mi_heap_zalloc_aligned_at(mi_heap_t *heap, size_t size, size_t alignment, size_t offset)
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.
char * mi_heap_strdup(mi_heap_t *heap, const char *s)
Duplicate a string in a specific heap.
void mi_thread_heap_release(mi_heap_t *heap)
Release a heap in the calling thread – promises to not allocate in that heap anymore.
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.
void * mi_heap_zalloc_aligned(mi_heap_t *heap, size_t size, 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_collect(mi_heap_t *heap, bool force)
Release outstanding resources in a specific heap.
mi_heap_t * mi_heap_main(void)
v3: the main heap (of the current sub-process)
void mi_heap_destroy(mi_heap_t *heap)
Destroy a heap, freeing all its still allocated blocks.
void * mi_heap_calloc_aligned_at(mi_heap_t *heap, size_t count, size_t size, size_t alignment, size_t offset)
mi_heap_t * mi_heap_new()
Create a new heap that can be used for allocation.
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?
void mi_heap_set_numa_affinity(mi_heap_t *heap, int numa_node)
v3: set NUMA affinity for a heap.
void * mi_heap_mallocn(mi_heap_t *heap, size_t count, size_t size)
Allocate count elements in a specific heap.
void * mi_heap_malloc(mi_heap_t *heap, size_t size)
Allocate 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_realloc(mi_heap_t *heap, void *p, size_t newsize)
mi_heap_t * mi_heap_get_backing()
v1,v2: Get the backing heap.
bool mi_heap_contains(const mi_heap_t *heap, const void *p)
v3: does a heap contain a specific pointer?
void * mi_heap_calloc_aligned(mi_heap_t *heap, size_t count, size_t size, size_t alignment)
void * mi_heap_reallocn(mi_heap_t *heap, void *p, size_t count, size_t size)
void * mi_heap_realloc_aligned(mi_heap_t *heap, void *p, size_t newsize, size_t alignment)
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_reallocf(mi_heap_t *heap, void *p, size_t newsize)
void * mi_heap_malloc_aligned_at(mi_heap_t *heap, size_t size, size_t alignment, size_t offset)
void * mi_realloc(void *p, size_t newsize)
Re-allocate memory to newsize bytes.
size_t mi_usable_size(void *p)
Return the available bytes in a memory block.
void * mi_expand(void *p, size_t newsize)
Try to re-allocate memory to newsize bytes in place.
size_t mi_thread_id_of(const void *p)
experimental: Return the current owner thread-id of the page containing a live allocation.
char * mi_strdup(const char *s)
Allocate and duplicate a string.
char * mi_strndup(const char *s, size_t n)
Allocate and duplicate a string up to n bytes.
void * mi_reallocf(void *p, size_t newsize)
Re-allocate memory to newsize bytes,.
void * mi_mallocn(size_t count, size_t size)
Allocate count elements of size bytes.
void * mi_calloc(size_t count, size_t size)
Allocate zero-initialized count elements of size bytes.
void mi_cfree(void *p)
Checked free: just as mi_free() but always checks if the pointer p belongs to our heap.
size_t mi_allocated_size(const void *p)
v3: Return the full size of the memory block containing p.
void * mi_reallocn(void *p, size_t count, size_t size)
Re-allocate memory to count elements of size bytes.
char * mi_realpath(const char *fname, char *resolved_name)
Resolve a file path name.
size_t mi_good_size(size_t size)
Return the full usable size of the block that an allocation of a given size would use.
void * mi_malloc(size_t size)
Allocate size bytes.
void * mi_zalloc(size_t size)
Allocate zero-initialized size bytes.
void mi_free(void *p)
Free previously allocated memory.
void mi_option_enable(mi_option_t option)
void mi_options_print_out(mi_output_fun *out, void *arg)
Print out all process info.
size_t mi_option_get_size(mi_option_t option)
bool mi_option_is_enabled(mi_option_t option)
void mi_option_set_enabled_default(mi_option_t option, bool enable)
long mi_option_get(mi_option_t option)
void mi_option_set_default(mi_option_t option, long value)
long mi_option_get_clamp(mi_option_t option, long min, long max)
void mi_option_set_enabled(mi_option_t option, bool enable)
void mi_option_disable(mi_option_t option)
void mi_options_print(void)
Print out all runtime parameters for mimalloc.
void mi_option_set(mi_option_t option, long value)
mi_option_t
Runtime options.
Definition mimalloc-doc.h:1800
@ mi_option_guarded_min
only used when building with MI_GUARDED: minimal rounded object size for guarded objects (=0)
Definition mimalloc-doc.h:1821
@ mi_option_abandoned_reclaim_on_free
v1,v2: allow to reclaim an abandoned segment on a free (=1)
Definition mimalloc-doc.h:1838
@ mi_option_purge_extend_delay
v1,v2: extend purge delay on each subsequent delay (=1)
Definition mimalloc-doc.h:1839
@ mi_option_allow_thp
Transparent huge pages: 0 disable for the process, 1 allow, 2 allow and avoid splitting on purge....
Definition mimalloc-doc.h:1818
@ mi_option_show_stats
Print statistics on termination.
Definition mimalloc-doc.h:1803
@ mi_option_use_numa_nodes
0 = use all available numa nodes, otherwise use at most N nodes.
Definition mimalloc-doc.h:1833
@ mi_option_page_max_reclaim
v3: don't reclaim pages of the same originating theap if we already own N pages (in that size class) ...
Definition mimalloc-doc.h:1851
@ mi_option_abandoned_page_purge
v1,v2: immediately purge delayed purges on thread termination
Definition mimalloc-doc.h:1831
@ mi_option_eager_commit_delay
v2: the first N segments per thread are not eagerly committed (but per page in the segment on demand)
Definition mimalloc-doc.h:1829
@ mi_option_eager_commit
v1,v2: eager commit segments? (after eager_commit_delay segments) (enabled by default).
Definition mimalloc-doc.h:1828
@ mi_option_visit_abandoned
v1,v2: allow visiting heap blocks from abandoned threads (=0)
Definition mimalloc-doc.h:1841
@ mi_option_unsafe_guarded_precise
disregard minimal alignment requirement to always place guarded blocks exactly in front of a guard pa...
Definition mimalloc-doc.h:1823
@ mi_option_os_tag
tag used for OS logging (macOS only for now) (=100)
Definition mimalloc-doc.h:1815
@ mi_option_arena_max_object_size
v3: set maximal object size that can be allocated in an arena (in KiB) (=2GiB on 64-bit).
Definition mimalloc-doc.h:1854
@ mi_option_minimal_purge_size
v3: set minimal purge size (in KiB) (=0). By default set to either 64 or 2048 if THP is enabled....
Definition mimalloc-doc.h:1853
@ _mi_option_last
Definition mimalloc-doc.h:1856
@ 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:1836
@ mi_option_page_cross_thread_max_reclaim
v3: don't reclaim pages across threads if we already own N pages (in that size class) (=16)
Definition mimalloc-doc.h:1852
@ mi_option_page_commit_on_demand
v3: commit page memory on-demand (=0)
Definition mimalloc-doc.h:1850
@ mi_option_guarded_sample_seed
can be set to allow for a (more) deterministic re-execution when a guard page is triggered (=0)
Definition mimalloc-doc.h:1825
@ mi_option_verbose
Print verbose messages.
Definition mimalloc-doc.h:1804
@ mi_option_allow_large_os_pages
allow large (2 or 4 MiB) OS pages, implies eager commit.
Definition mimalloc-doc.h:1812
@ mi_option_arena_purge_mult
multiplier for purge_delay for the purging delay for arenas (=10)
Definition mimalloc-doc.h:1837
@ mi_option_target_segments_per_thread
v1,v2: experimental (=0)
Definition mimalloc-doc.h:1842
@ mi_option_generic_collect
collect heaps every N (=10000) generic allocation calls
Definition mimalloc-doc.h:1817
@ 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:1816
@ mi_option_guarded_max
only used when building with MI_GUARDED: maximal rounded object size for guarded objects (=0)
Definition mimalloc-doc.h:1822
@ 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:1813
@ mi_option_reserve_huge_os_pages_at
Reserve N huge OS pages at a specific NUMA node N.
Definition mimalloc-doc.h:1810
@ mi_option_pagemap_commit
v3: commit the full pagemap (to always catch invalid pointer uses) (=0)
Definition mimalloc-doc.h:1849
@ mi_option_max_segment_reclaim
v2: max. percentage of the abandoned segments can be reclaimed per try (=10%)
Definition mimalloc-doc.h:1835
@ mi_option_max_vabits
v3: max user space virtual address bits to consider (=48)
Definition mimalloc-doc.h:1848
@ 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:1814
@ mi_option_page_reclaim_on_free
v3: reclaim abandoned pages on a free (=0). -1 disallowr always, 0 allows if the page originated from...
Definition mimalloc-doc.h:1845
@ mi_option_reserve_huge_os_pages
reserve N huge OS pages (1GiB pages) at startup
Definition mimalloc-doc.h:1809
@ mi_option_page_max_candidates
v3: max candidate pages to consider for allocation (=4)
Definition mimalloc-doc.h:1847
@ mi_option_disallow_os_alloc
1 = do not use OS memory for allocation (but only programmatically reserved arenas)
Definition mimalloc-doc.h:1834
@ 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:1832
@ mi_option_disallow_arena_alloc
1 = do not use arena's for allocation (except if using specific arena id's)
Definition mimalloc-doc.h:1840
@ mi_option_guarded_sample_rate
guard an object in the min/max range about every N requested bytes (=0)
Definition mimalloc-doc.h:1824
@ mi_option_max_errors
issue at most N error messages
Definition mimalloc-doc.h:1805
@ mi_option_page_full_retain
v3: retain N full (small) pages per size class (=2). Use -1 for infinite (as in v1,...
Definition mimalloc-doc.h:1846
@ mi_option_max_warnings
issue at most N warning messages
Definition mimalloc-doc.h:1806
@ mi_option_show_errors
Print error messages.
Definition mimalloc-doc.h:1802
@ 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:1811
@ mi_option_arena_eager_commit
eager commit arenas? Use 2 to enable just on overcommit systems (=2)
Definition mimalloc-doc.h:1830
size_t mi_malloc_usable_size(const void *p)
void mi_free_aligned(void *p, size_t alignment)
Free an object that was allocated aligned.
void * mi_aligned_offset_recalloc(void *p, size_t newcount, size_t size, size_t alignment, size_t offset)
void mi_free_aligned_sized(void *p, size_t alignment, size_t size)
Corresponds to C23 free_aligned_sized.
void * mi_aligned_alloc(size_t alignment, size_t size)
Corresponds to C11 aligned_alloc.
size_t mi_malloc_size(const void *p)
void * mi_valloc(size_t size)
void * mi_pvalloc(size_t size)
void * mi__expand(void *p, size_t newsize)
int mi_wdupenv_s(unsigned short **buf, size_t *size, const unsigned short *name)
void * mi_memalign(size_t alignment, size_t size)
void mi_free_size_aligned(void *p, size_t size, size_t alignment)
unsigned char * mi_mbsdup(const unsigned char *s)
int mi_reallocarr(void *p, size_t count, size_t size)
Corresponds to reallocarr in NetBSD.
size_t mi_malloc_good_size(size_t size)
unsigned short * mi_wcsdup(const unsigned short *s)
int mi_dupenv_s(char **buf, size_t *size, const char *name)
void mi_free_sized(void *p, size_t size)
Free a block that was allocated with a known size.
int mi_posix_memalign(void **p, size_t alignment, size_t size)
int mi__posix_memalign(void **p, size_t alignment, size_t size)
void * mi_reallocarray(void *p, size_t count, size_t size)
Correspond s to reallocarray in FreeBSD.
void mi_free_size(void *p, size_t size)
void * mi_aligned_recalloc(void *p, size_t newcount, size_t size, size_t alignment)
void mi_free_sized_aligned(void *p, size_t size, size_t alignment)
Free an object that was allocated aligned.
mi_profiler_t * mi_pprof_profiler_new(size_t initial_threshold, const char *base_file_name, size_t alloc_interval_size, size_t inuse_interval_size, size_t time_interval_secs)
experimental: Create the built-in pprof-compatible profiler.
bool mi_profile(mi_profiler_t *profiler)
experimental: Attach a profiler to the current and future heaps of the main subprocess.
void mi_usdt_profiler_delete(mi_profiler_t *profiler)
experimental: Delete a USDT profiler.
bool mi_profiler_start(mi_profiler_t *profiler)
experimental: Start sampling with an attached profiler.
struct mi_profiler_s mi_profiler_t
Profiler type. Custom profiler fields and callback types are defined in <mimalloc-profile....
Definition mimalloc-doc.h:1640
void mi_profiler_snapshot(mi_profiler_t *profiler)
experimental: Take a snapshot of the current profile.
bool mi_profiler_stop(mi_profiler_t *profiler)
experimental: Stop sampling.
void mi_heap_profile_disable(mi_heap_t *heap)
experimental: Exclude a heap from profiling, even when a profiler is subsequently attached to its sub...
bool mi_subproc_profile_detach(mi_subproc_id_t subproc_id, mi_profiler_t *profiler)
experimental: Detach a profiler from a particular subprocess and its heaps.
bool mi_subproc_profile(mi_subproc_id_t subproc_id, mi_profiler_t *profiler)
experimental: Attach a profiler to the current and future heaps of a particular subprocess.
bool mi_heap_profile(mi_heap_t *heap, mi_profiler_t *profiler)
experimental: Attach a profiler to a particular heap, or pass NULL as the profiler to detach all prof...
bool mi_heap_profile_detach(mi_heap_t *heap, mi_profiler_t *profiler)
experimental: Detach a profiler from a particular heap.
mi_profiler_t * mi_usdt_profiler_new(size_t sample_rate)
experimental: Create a new USDT profiler (on Linux x64 and arm64).
bool mi_profile_detach(mi_profiler_t *profiler)
experimental: Detach a profiler from the main subprocess and its heaps.
void mi_pprof_profiler_delete(mi_profiler_t *profiler)
experimental: Delete a built-in profiler created by mi_pprof_profiler_new().
void * mi_umalloc_small(size_t size, size_t *pusable_size)
As mi_malloc_small(), additionally reporting the usable size on success.
void * mi_urealloc_aligned(void *p, size_t newsize, size_t alignment, size_t *pusable_size_pre, size_t *pusable_size_post)
As mi_realloc_aligned(), additionally reporting the old and new usable sizes (as mi_urealloc()).
void mi_ufree(void *p, size_t *pusable_size)
Free p and report its usable size, or 0 if p is NULL.
void * mi_ucalloc(size_t count, size_t size, size_t *pusable_size)
Allocate count zero-initialized elements of size bytes and report the usable size.
void * mi_uzalloc_small(size_t size, size_t *pusable_size)
As mi_zalloc_small(), additionally reporting the usable size on success.
void * mi_uzalloc_aligned(size_t size, size_t alignment, size_t *pusable_size)
As mi_zalloc_aligned(), additionally reporting the usable size on success.
void * mi_umalloc(size_t size, size_t *pusable_size)
Allocate size bytes and report the usable size through pusable_size.
void * mi_uzalloc(size_t size, size_t *pusable_size)
Allocate size zero-initialized bytes and report the usable size through pusable_size.
void * mi_umalloc_aligned(size_t size, size_t alignment, size_t *pusable_size)
As mi_malloc_aligned(), additionally reporting the usable size on success.
void * mi_urealloc(void *p, size_t newsize, size_t *pusable_size_pre, size_t *pusable_size_post)
Reallocate p to newsize bytes and report the old and new usable sizes.
void mi_free_small_nonnull(void *p)
v3: Can be used to free an object that was allocated with mi_malloc_small() or any allocation with a ...
void mi_free_small(void *p)
v3: Can be used to free an object that was allocated with mi_malloc_small() or any allocation with a ...
size_t mi_wsize_from_size(size_t size)
v3: Convert a byte size to a number of sizeof(size_t) words, rounding up.
void * mi_zalloc_small(size_t size)
Allocate a zero initialized small object.
void * mi_wzalloc_small(size_t wsize)
v3: As mi_wmalloc_small(), but zero-initialize the allocation.
void * mi_malloc_small(size_t size)
Allocate a small object.
void mi_free_small_local(void *p)
v3: As mi_free_small(), but the block's page must be owned by the calling thread.
void * mi_wmalloc_small(size_t wsize)
v3: Allocate a small object with its size expressed in machine words.
void mi_free_small_local_nonnull(void *p)
As mi_free_small_local(), but p must not be NULL.
size_t version
initialize with `MI_STAT_VERSION (so linking dynamically with a separately compiled mimalloc is safe)
Definition mimalloc-doc.h:1407
size_t size
initialize with sizeof(mi_stats_t) (so linking dynamically with a separately compiled mimalloc is saf...
Definition mimalloc-doc.h:1405
void mi_process_info_print_out(mi_output_fun *out, void *arg)
Print out all process info.
void mi_theap_stats_merge_to_heap(mi_theap_t *theap)
v3: Merge a theap's statistics into its parent heap and clear the theap counters.
void mi_subproc_heap_stats_print_out(mi_subproc_id_t subproc_id, mi_output_fun *out, void *arg)
v3: Print statistics for a given subprocess with each heap separately printed.
bool mi_heap_stats_get(mi_heap_t *heap, mi_stats_t *stats)
v3: Return statistics for a given heap.
void mi_stats_print(void *out)
void mi_stats_reset(void)
v1,v2: Reset statistics.
void mi_stats_print_out(mi_output_fun *out, void *arg)
Print statistics of the current subprocess aggregated over all its heaps.
void mi_subproc_stats_print_out(mi_subproc_id_t subproc_id, mi_output_fun *out, void *arg)
v3: Print the subproc statistics aggregated over all its heaps.
void mi_heap_stats_merge_to_subproc(mi_heap_t *heap)
v3: xplicitly merge the statistics of the current heap with the subprocess.
bool mi_subproc_stats_get(mi_subproc_id_t subproc_id, mi_stats_t *stats)
v3: Get statistics for a given subprocess aggregated over all its heaps.
char * mi_stats_as_json(mi_stats_t *stats, size_t buf_size, char *buf)
v3: Show the given statistics as JSON.
void mi_stats_init(mi_stats_t *stats)
Zero all counters and initialize the size and version fields of stats.
bool mi_theap_stats_get(mi_theap_t *theap, mi_stats_t *stats)
v3: Get statistics for a theap belonging to the calling thread.
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).
void mi_stats_merge(void)
v1,v2: Merge thread local statistics with the main statistics and reset.
bool mi_subproc_stats_get_exclusive(mi_subproc_id_t subproc_id, mi_stats_t *stats)
v3: Get subprocess statistics without aggregating its heaps.
bool mi_stats_get(mi_stats_t *stats)
Get the statistics for the current subprocess aggregated over all its heaps.
void mi_thread_stats_print_out(mi_output_fun *out, void *arg)
char * mi_heap_stats_get_json(mi_heap_t *heap, size_t buf_size, char *buf)
v3: Get the statistics for a heap as JSON.
char * mi_subproc_stats_get_json(mi_subproc_id_t subproc_id, size_t buf_size, char *buf)
v3: Show the subproc statistics aggregated over all its heaps as JSON.
char * mi_stats_get_json(size_t buf_size, char *buf)
Get the statistics for the current subprocess aggregated over all its heaps as JSON.
size_t mi_stats_get_bin_size(size_t bin)
v3: Return the block size for the given bin.
void mi_stats_header_init(mi_stats_t *stats)
Initialize only the size and version fields of stats, leaving counters unchanged.
void mi_process_info_print(void)
Print out all process info.
void mi_heap_stats_print_out(mi_heap_t *heap, mi_output_fun *out, void *arg)
v3: Show the heap statistics as JSON.
Statistics. See include/mimalloc-stats.h for the full definition.
Definition mimalloc-doc.h:1403
mi_subproc_id_t mi_subproc_main(void)
Get the main sub-process identifier.
bool mi_heap_visit_fun(mi_heap_t *heap, void *arg)
The type of a heap visitor function.
Definition mimalloc-doc.h:1215
mi_subproc_id_t mi_subproc_new(void)
Create a fresh sub-process (with no associated threads yet).
void * mi_subproc_id_t
A process can associate threads with sub-processes.
Definition mimalloc-doc.h:1184
void mi_subproc_delete(mi_subproc_id_t subproc)
v1,v2: Delete a previously created sub-process.
mi_subproc_id_t mi_subproc_current(void)
Get the current sub-process identifier of this thread.
void mi_subproc_destroy(mi_subproc_id_t subproc)
v3: Destroy a previously created sub-process.
void mi_subproc_add_current_thread(mi_subproc_id_t subproc)
Add the current thread to the given sub-process.
bool mi_subproc_visit_heaps(mi_subproc_id_t subproc, mi_heap_visit_fun *visitor, void *arg)
Visit all heaps belonging to a subprocess.
mi_theap_t * mi_theap_set_default(mi_theap_t *theap)
Set the default thread-local theap to use in the current thread for mi_malloc() et al.
void mi_theap_guarded_set_size_bound(mi_theap_t *theap, size_t min, size_t max)
experimental: Set inclusive size bounds in bytes for guarded allocations in this theap.
void * mi_theap_realloc(mi_theap_t *theap, void *p, size_t newsize)
void * mi_theap_rezalloc(mi_theap_t *theap, void *p, size_t oldsize, size_t newsize)
As mi_rezalloc(), using a theap belonging to the calling thread.
void * mi_theap_malloc_small(mi_theap_t *theap, size_t size)
Allocate a small object in a specific theap.
void * mi_theap_realloc_aligned(mi_theap_t *theap, void *p, size_t newsize, size_t alignment)
As mi_realloc_aligned(), using a theap belonging to the calling thread.
void mi_theap_guarded_set_sample_rate(mi_theap_t *theap, size_t sample_rate, size_t seed)
experimental: Set guarded-allocation sampling for a theap belonging to the calling thread.
void * mi_theap_wmalloc_small(mi_theap_t *theap, size_t wsize)
As mi_wmalloc_small(), using a non-NULL theap belonging to the calling thread.
mi_theap_t * mi_theap_get_default()
Get the default theap that is used for mi_malloc() et al.
void * mi_theap_malloc_aligned(mi_theap_t *theap, size_t size, size_t alignment)
mi_heap_t * mi_theap_get_heap(const mi_theap_t *theap)
Return the heap that owns a theap.
struct mi_theap_s mi_theap_t
Type of thread-local heaps.
Definition mimalloc-doc.h:1966
bool mi_theap_visit_blocks(const mi_theap_t *theap, bool visit_blocks, mi_block_visit_fun *visitor, void *arg)
void mi_theap_collect(mi_theap_t *theap, bool force)
Release outstanding resources in a specific theap.
void mi_theap_delete(mi_theap_t *theap)
experimental: Abandon a theap's pages and delete the theap, preserving its heap and live blocks.
void * mi_theap_wzalloc_small(mi_theap_t *theap, size_t wsize)
As mi_wzalloc_small(), using a non-NULL theap belonging to the calling thread.
void * mi_theap_zalloc_aligned(mi_theap_t *theap, size_t size, size_t alignment)
As mi_zalloc_aligned(), using a theap belonging to the calling thread.
void * mi_theap_zalloc(mi_theap_t *theap, size_t size)
Allocate zero-initialized in a specific heap.
void * mi_theap_zalloc_small(mi_theap_t *theap, size_t size)
Allocate a small object in a specific theap.
void mi_theap_quiescent_abandon(mi_theap_t *theap)
experimental: Abandon all pages, preserving the theap and live blocks for reuse.
mi_theap_t * mi_heap_get_theap(mi_heap_t *heap)
Return the thread-local theap for the given heap.
void * mi_theap_malloc(mi_theap_t *theap, size_t size)
Allocate in a specific theap.
void * mi_theap_rezalloc_aligned(mi_theap_t *theap, void *p, size_t oldsize, size_t newsize, size_t alignment)
As mi_rezalloc_aligned(), using a theap belonging to the calling thread.
void * mi_theap_calloc(mi_theap_t *theap, size_t count, size_t size)
void * mi_rezalloc_aligned(void *p, size_t oldsize, size_t newsize, size_t alignment)
As mi_rezalloc() but the returned block is aligned to alignment.
void * mi_recalloc(void *p, size_t oldcount, size_t newcount, size_t size)
Re-allocate memory to newcount elements of size bytes, with the elements from oldcount initialized to...
void * mi_heap_rezalloc_aligned(mi_heap_t *heap, void *p, size_t oldsize, size_t newsize, size_t alignment)
As mi_rezalloc_aligned() but allocates in a specific heap.
void * mi_heap_recalloc_aligned_at(mi_heap_t *heap, void *p, size_t oldcount, size_t newcount, size_t size, size_t alignment, size_t offset)
As mi_recalloc_aligned_at() but allocates in a specific heap.
void * mi_heap_rezalloc_aligned_at(mi_heap_t *heap, void *p, size_t oldsize, size_t newsize, size_t alignment, size_t offset)
As mi_rezalloc_aligned_at() but allocates in a specific heap.
void * mi_heap_recalloc_aligned(mi_heap_t *heap, void *p, size_t oldcount, size_t newcount, size_t size, size_t alignment)
As mi_recalloc_aligned() but allocates in a specific heap.
void * mi_recalloc_aligned(void *p, size_t oldcount, size_t newcount, size_t size, size_t alignment)
As mi_recalloc() but the returned block is aligned to alignment.
void * mi_rezalloc(void *p, size_t oldsize, size_t newsize)
Re-allocate memory to newsize bytes, with the memory from oldsize initialized to zero.
void * mi_recalloc_aligned_at(void *p, size_t oldcount, size_t newcount, size_t size, size_t alignment, size_t offset)
As mi_recalloc() but the returned block is aligned by alignment at a specified offset.
void * mi_heap_recalloc(mi_heap_t *heap, void *p, size_t oldcount, size_t newcount, size_t size)
As mi_recalloc() but allocates in a specific heap.
void * mi_rezalloc_aligned_at(void *p, size_t oldsize, size_t newsize, size_t alignment, size_t offset)
As mi_rezalloc() but the returned block is aligned by alignment at a specified offset.
void * mi_heap_rezalloc(mi_heap_t *heap, void *p, size_t oldsize, size_t newsize)
As mi_rezalloc() but allocates in a specific heap.