mi-malloc 3.6/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
131
132
136
137
144void mi_free(void* p);
145
150void mi_cfree(void* p);
151
156void* mi_malloc(size_t size);
157
162void* mi_zalloc(size_t size);
163
173void* mi_calloc(size_t count, size_t size);
174
188void* mi_realloc(void* p, size_t newsize);
189
203void* mi_expand(void* p, size_t newsize);
204
214void* mi_mallocn(size_t count, size_t size);
215
225void* mi_reallocn(void* p, size_t count, size_t size);
226
243void* mi_reallocf(void* p, size_t newsize);
244
245
254char* mi_strdup(const char* s);
255
265char* mi_strndup(const char* s, size_t n);
266
279char* mi_realpath(const char* fname, char* resolved_name);
280
294size_t mi_usable_size(void* p);
295
306size_t mi_thread_id_of(const void* p);
307
317size_t mi_good_size(size_t size);
318
320
321
322// ------------------------------------------------------
323// Allocation with block sizes
324// ------------------------------------------------------
325
332
336void* mi_umalloc(size_t size, size_t* block_size);
337
341void* mi_ucalloc(size_t count, size_t size, size_t* block_size);
342
347void* mi_urealloc(void* p, size_t newsize, size_t* block_size_pre, size_t* block_size_post);
348
351void mi_ufree(void* p, size_t* block_size);
352
354void* mi_umalloc_aligned(size_t size, size_t alignment, size_t* block_size);
355
357void* mi_uzalloc_aligned(size_t size, size_t alignment, size_t* block_size);
358
361void* mi_umalloc_small(size_t size, size_t* block_size);
362
365void* mi_uzalloc_small(size_t size, size_t* block_size);
366
368
369// ------------------------------------------------------
370// Aligned allocation
371// ------------------------------------------------------
372
385
403void* mi_malloc_aligned(size_t size, size_t alignment);
404void* mi_zalloc_aligned(size_t size, size_t alignment);
405void* mi_calloc_aligned(size_t count, size_t size, size_t alignment);
406void* mi_realloc_aligned(void* p, size_t newsize, size_t alignment);
407
419void* mi_malloc_aligned_at(size_t size, size_t alignment, size_t offset);
420void* mi_zalloc_aligned_at(size_t size, size_t alignment, size_t offset);
421void* mi_calloc_aligned_at(size_t count, size_t size, size_t alignment, size_t offset);
422void* mi_realloc_aligned_at(void* p, size_t newsize, size_t alignment, size_t offset);
423
425
426
436
450#define mi_malloc_tp(tp) ((tp*)mi_malloc_csize(sizeof(tp)))
451
458#define mi_free_tp(tp,p) (mi_free_csize(p,sizeof(tp)))
459
461#define mi_zalloc_tp(tp) ((tp*)mi_zalloc_csize(sizeof(tp)))
462
464#define mi_calloc_tp(tp,count) ((tp*)mi_calloc(count,sizeof(tp)))
465
467#define mi_mallocn_tp(tp,count) ((tp*)mi_mallocn(count,sizeof(tp)))
468
470#define mi_reallocn_tp(p,tp,count) ((tp*)mi_reallocn(p,count,sizeof(tp)))
471
473#define mi_heap_malloc_tp(tp,hp) ((tp*)mi_heap_malloc(hp,sizeof(tp)))
474
476#define mi_heap_zalloc_tp(tp,hp) ((tp*)mi_heap_zalloc(hp,sizeof(tp)))
477
479#define mi_heap_calloc_tp(tp,hp,count) ((tp*)mi_heap_calloc(hp,count,sizeof(tp)))
480
482#define mi_heap_mallocn_tp(tp,hp,count) ((tp*)mi_heap_mallocn(hp,count,sizeof(tp)))
483
485#define mi_heap_reallocn_tp(tp,hp,p,count) ((tp*)mi_heap_reallocn(p,count,sizeof(tp)))
486
488#define mi_heap_recalloc_tp(tp,hp,p,count) ((tp*)mi_heap_recalloc(p,count,sizeof(tp)))
489
491
505
511void* mi_malloc_csize(size_t size);
512
513void* mi_zalloc_csize(size_t size);
514
515void* mi_theap_malloc_csize(mi_theap_t* theap, size_t size);
516
517void* mi_theap_zalloc_csize(mi_theap_t* theap, size_t size);
518
525void mi_free_csize(void* p, size_t size);
526
533void mi_free_csize_nonnull(void* p, size_t size);
534
538void mi_free_csize_aligned(void* p, size_t size, size_t aligned);
539
541void mi_free_csize_aligned_nonnull(void* p, size_t size, size_t aligned);
542
544
554
565void* mi_recalloc(void* p, size_t count, size_t size);
566
567void* mi_rezalloc(void* p, size_t newsize);
568void* mi_recalloc(void* p, size_t newcount, size_t size) ;
569
570void* mi_rezalloc_aligned(void* p, size_t newsize, size_t alignment);
571void* mi_rezalloc_aligned_at(void* p, size_t newsize, size_t alignment, size_t offset);
572void* mi_recalloc_aligned(void* p, size_t newcount, size_t size, size_t alignment);
573void* mi_recalloc_aligned_at(void* p, size_t newcount, size_t size, size_t alignment, size_t offset);
574
575void* mi_heap_rezalloc(mi_heap_t* heap, void* p, size_t newsize);
576void* mi_heap_recalloc(mi_heap_t* heap, void* p, size_t newcount, size_t size);
577
578void* mi_heap_rezalloc_aligned(mi_heap_t* heap, void* p, size_t newsize, size_t alignment);
579void* mi_heap_rezalloc_aligned_at(mi_heap_t* heap, void* p, size_t newsize, size_t alignment, size_t offset);
580void* mi_heap_recalloc_aligned(mi_heap_t* heap, void* p, size_t newcount, size_t size, size_t alignment);
581void* mi_heap_recalloc_aligned_at(mi_heap_t* heap, void* p, size_t newcount, size_t size, size_t alignment, size_t offset);
582
584
585
586
607
613struct mi_heap_s;
614
620typedef struct mi_heap_s mi_heap_t;
621
624
640
656
671
677
682
690
694void mi_heap_set_numa_affinity(mi_heap_t* heap, int numa_node);
695
698void mi_heap_set_debug_fill_preserve(mi_heap_t* heap, size_t preserve);
699
706
712mi_heap_t* mi_heap_of(const void* p);
713
718bool mi_heap_contains(const mi_heap_t* heap, const void* p);
719
723bool mi_any_heap_contains(const void* p);
724
725
731bool mi_is_in_heap_region(const void* p);
732
738bool mi_check_owned(const void* p);
739
746bool mi_heap_contains_block(mi_heap_t* heap, const void* p);
747
754bool mi_heap_check_owned(mi_heap_t* heap, const void* p);
755
757void mi_heap_collect(mi_heap_t* heap, bool force);
758
761void* mi_heap_malloc(mi_heap_t* heap, size_t size);
762
766void* mi_heap_malloc_small(mi_heap_t* heap, size_t size);
767
770void* mi_heap_zalloc(mi_heap_t* heap, size_t size);
771
775void* mi_heap_zalloc_small(mi_heap_t* heap, size_t size);
776
779void* mi_heap_calloc(mi_heap_t* heap, size_t count, size_t size);
780
783void* mi_heap_mallocn(mi_heap_t* heap, size_t count, size_t size);
784
787char* mi_heap_strdup(mi_heap_t* heap, const char* s);
788
791char* mi_heap_strndup(mi_heap_t* heap, const char* s, size_t n);
792
795char* mi_heap_realpath(mi_heap_t* heap, const char* fname, char* resolved_name);
796
797void* mi_heap_realloc(mi_heap_t* heap, void* p, size_t newsize);
798void* mi_heap_reallocn(mi_heap_t* heap, void* p, size_t count, size_t size);
799void* mi_heap_reallocf(mi_heap_t* heap, void* p, size_t newsize);
800
801void* mi_heap_malloc_aligned(mi_heap_t* heap, size_t size, size_t alignment);
802void* mi_heap_malloc_aligned_at(mi_heap_t* heap, size_t size, size_t alignment, size_t offset);
803void* mi_heap_zalloc_aligned(mi_heap_t* heap, size_t size, size_t alignment);
804void* mi_heap_zalloc_aligned_at(mi_heap_t* heap, size_t size, size_t alignment, size_t offset);
805void* mi_heap_calloc_aligned(mi_heap_t* heap, size_t count, size_t size, size_t alignment);
806void* mi_heap_calloc_aligned_at(mi_heap_t* heap, size_t count, size_t size, size_t alignment, size_t offset);
807void* mi_heap_realloc_aligned(mi_heap_t* heap, void* p, size_t newsize, size_t alignment);
808void* mi_heap_realloc_aligned_at(mi_heap_t* heap, void* p, size_t newsize, size_t alignment, size_t offset);
809
811
812
813
818
819
822typedef struct mi_heap_area_s {
823 void* blocks;
824 size_t reserved;
825 size_t committed;
826 size_t used;
827 size_t block_size;
831
839typedef bool (mi_block_visit_fun)(const mi_heap_t* heap, const mi_heap_area_t* area, void* block, size_t block_size, void* arg);
840
857bool mi_heap_visit_blocks(const mi_heap_t* heap, bool visit_blocks, mi_block_visit_fun* visitor, void* arg);
858
862bool mi_heap_visit_abandoned_blocks(mi_heap_t* heap, bool visit_blocks, mi_block_visit_fun* visitor, void* arg);
863
867bool mi_unsafe_heap_page_is_under_utilized(mi_heap_t* heap, void* p, size_t perc_threshold);
868
884bool mi_abandoned_visit_blocks(mi_subproc_id_t subproc_id, int heap_tag, bool visit_blocks, mi_block_visit_fun* visitor, void* arg);
885
887
888// ------------------------------------------------------
889// Arenas
890// ------------------------------------------------------
891
899
901typedef int mi_arena_id_t;
902
911int mi_reserve_os_memory(size_t size, bool commit, bool allow_large);
912
920int mi_reserve_os_memory_ex(size_t size, bool commit, bool allow_large, bool exclusive, mi_arena_id_t* arena_id);
921
934int mi_reserve_huge_os_pages_interleave(size_t pages, size_t numa_nodes, size_t timeout_msecs);
935
948int mi_reserve_huge_os_pages_at(size_t pages, int numa_node, size_t timeout_msecs);
949
954int mi_reserve_huge_os_pages(size_t pages, double max_secs, size_t* pages_reserved);
955
963int 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);
964
968
971size_t mi_arena_min_size(void);
972
976
988bool mi_manage_os_memory(void* start, size_t size, bool is_committed, bool is_large, bool is_zero, int numa_node);
989
1000bool 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);
1001
1007typedef bool (mi_commit_fun_t)(bool commit, void* start, size_t size, bool* is_zero, void* user_arg);
1008
1014bool mi_manage_memory(void* start, size_t size, bool is_committed, bool is_pinned, bool is_zero, int numa_node, bool exclusive,
1015 mi_commit_fun_t* commit_fun, void* commit_fun_arg, mi_arena_id_t* arena_id);
1016
1017
1020
1023
1027
1032void* mi_arena_area(mi_arena_id_t arena_id, size_t* size);
1033
1036bool mi_arena_contains(mi_arena_id_t arena_id, const void* p);
1037
1042
1054mi_heap_t* mi_heap_new_ex(int heap_tag, bool allow_destroy, mi_arena_id_t arena_id);
1055
1057
1058
1067
1072typedef void* mi_subproc_id_t;
1073
1076
1079
1083
1088
1094
1099
1103typedef bool (mi_heap_visit_fun)(mi_heap_t* heap, void* arg);
1104
1111
1113
1114
1115// ------------------------------------------------------
1116// Extended functionality
1117// ------------------------------------------------------
1118
1123
1126#define MI_SMALL_WSIZE_MAX 128
1127
1131#define MI_SMALL_SIZE_MAX (MI_SMALL_WSIZE_MAX*sizeof(size_t))
1132
1136int mi_version(void);
1137
1145void mi_collect(bool force);
1146
1149void mi_collect_reduce(size_t target_thread_owned);
1150
1153
1157
1164
1170
1175
1184
1191typedef void (mi_deferred_free_fun)(bool force, unsigned long long heartbeat, void* arg);
1192
1208void mi_register_deferred_free(mi_deferred_free_fun* deferred_free, void* arg);
1209
1215typedef void (mi_output_fun)(const char* msg, void* arg);
1216
1223void mi_register_output(mi_output_fun* out, void* arg);
1224
1230typedef void (mi_error_fun)(int err, void* arg);
1231
1252void mi_register_error(mi_error_fun* errfun, void* arg);
1253
1261void* mi_malloc_small(size_t size);
1262
1273void* mi_wmalloc_small(size_t wsize);
1274
1277void* mi_wzalloc_small(size_t wsize);
1278
1281size_t mi_wsize_from_size(size_t size);
1282
1290void* mi_zalloc_small(size_t size);
1291
1307void mi_free_small(void* p);
1308
1325
1329
1332
1334
1335
1336
1337
1338
1339// ------------------------------------------------------
1340// Statistics
1341// ------------------------------------------------------
1342
1346
1348#define MI_STAT_VERSION 4
1349
1359#define mi_stats_t_decl(name)
1360
1364 size_t size;
1366 size_t version;
1367};
1368
1370typedef struct mi_stats_s mi_stats_t;
1371
1373void mi_stats_header_init(mi_stats_t* stats);
1374
1377void mi_stats_init(mi_stats_t* stats);
1378
1379
1383
1389
1403void 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);
1404
1405
1410void mi_stats_print(void* out);
1411
1417void mi_stats_print_out(mi_output_fun* out, void* arg);
1418
1422
1428bool mi_stats_get(mi_stats_t* stats);
1429
1435char* mi_stats_get_json(size_t buf_size, char* buf);
1436
1438size_t mi_stats_get_bin_size(size_t bin);
1439
1446bool mi_heap_stats_get(mi_heap_t* heap, mi_stats_t* stats);
1447
1454char* 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
1455
1461
1466
1473bool mi_subproc_stats_get(mi_subproc_id_t subproc_id, mi_stats_t* stats);
1474
1478bool mi_subproc_stats_get_exclusive(mi_subproc_id_t subproc_id, mi_stats_t* stats);
1479
1483bool mi_theap_stats_get(mi_theap_t* theap, mi_stats_t* stats);
1484
1488
1495char* 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
1496
1502
1503
1509
1516char* mi_stats_as_json( mi_stats_t* stats, size_t buf_size, char* buf);
1517
1521
1525
1527
1528// ------------------------------------------------------
1529// Heap Profiling
1530// ------------------------------------------------------
1531
1595
1597typedef struct mi_profiler_s mi_profiler_t;
1598
1610mi_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);
1611
1616
1622
1628
1634
1638
1642
1646
1651
1653
1654// ------------------------------------------------------
1655// Runtime Options
1656// ------------------------------------------------------
1657
1662
1666
1673
1674
1679typedef enum mi_option_e {
1680 // stable options
1686
1687 // advanced options
1698
1699 // guard pages
1705
1706 // experimental options
1722
1723 // v3 options
1734
1736} mi_option_t;
1737
1738
1742void mi_option_set_enabled(mi_option_t option, bool enable);
1744
1746long mi_option_get_clamp(mi_option_t option, long min, long max);
1748
1749void mi_option_set(mi_option_t option, long value);
1750void mi_option_set_default(mi_option_t option, long value);
1751
1753
1766
1768struct mi_theap_s;
1769
1771typedef struct mi_theap_s mi_theap_t;
1772
1784
1786void mi_theap_collect(mi_theap_t* theap, bool force);
1787
1791
1796
1802
1806
1809void* mi_theap_malloc(mi_theap_t* theap, size_t size);
1810
1814void* mi_theap_malloc_small(mi_theap_t* theap, size_t size);
1815
1818void* mi_theap_wmalloc_small(mi_theap_t* theap, size_t wsize);
1819
1822void* mi_theap_wzalloc_small(mi_theap_t* theap, size_t wsize);
1823
1826void* mi_theap_zalloc(mi_theap_t* theap, size_t size);
1827
1831void* mi_theap_zalloc_small(mi_theap_t* theap, size_t size);
1832
1833void* mi_theap_calloc(mi_theap_t* theap, size_t count, size_t size);
1834void* mi_theap_malloc_aligned(mi_theap_t* theap, size_t size, size_t alignment);
1835void* mi_theap_realloc(mi_theap_t* theap, void* p, size_t newsize);
1836
1838void* mi_theap_zalloc_aligned(mi_theap_t* theap, size_t size, size_t alignment);
1839
1842void* mi_theap_rezalloc(mi_theap_t* theap, void* p, size_t newsize);
1843
1845void* mi_theap_realloc_aligned(mi_theap_t* theap, void* p, size_t newsize, size_t alignment);
1846
1849void* mi_theap_rezalloc_aligned(mi_theap_t* theap, void* p, size_t newsize, size_t alignment);
1850
1854void mi_theap_guarded_set_sample_rate(mi_theap_t* theap, size_t sample_rate, size_t seed);
1855
1858void mi_theap_guarded_set_size_bound(mi_theap_t* theap, size_t min, size_t max);
1859
1863bool mi_theap_visit_blocks(const mi_theap_t* theap, bool visit_blocks, mi_block_visit_fun* visitor, void* arg);
1864
1866
1867
1873
1874void* mi__expand(void* p, size_t newsize);
1875
1876size_t mi_malloc_size(const void* p);
1877size_t mi_malloc_good_size(size_t size);
1878size_t mi_malloc_usable_size(const void *p);
1879
1880int mi_posix_memalign(void** p, size_t alignment, size_t size);
1881int mi__posix_memalign(void** p, size_t alignment, size_t size);
1882void* mi_memalign(size_t alignment, size_t size);
1883void* mi_valloc(size_t size);
1884void* mi_pvalloc(size_t size);
1885
1888void* mi_aligned_alloc(size_t alignment, size_t size);
1889
1892void mi_free_sized(void* p, size_t size);
1893
1896void mi_free_aligned_sized(void* p, size_t alignment, size_t size);
1897
1898unsigned short* mi_wcsdup(const unsigned short* s);
1899unsigned char* mi_mbsdup(const unsigned char* s);
1900int mi_dupenv_s(char** buf, size_t* size, const char* name);
1901int mi_wdupenv_s(unsigned short** buf, size_t* size, const unsigned short* name);
1902
1905void* mi_reallocarray(void* p, size_t count, size_t size);
1906
1908int mi_reallocarr(void* p, size_t count, size_t size);
1909
1910void* mi_aligned_recalloc(void* p, size_t newcount, size_t size, size_t alignment);
1911void* mi_aligned_offset_recalloc(void* p, size_t newcount, size_t size, size_t alignment, size_t offset);
1912
1924void mi_free_size(void* p, size_t size);
1925
1936void mi_free_size_nonnull(void* p, size_t size);
1937
1943void mi_free_size_aligned(void* p, size_t size, size_t alignment);
1944
1949void mi_free_aligned(void* p, size_t alignment);
1950
1952
1965
1967void* mi_new(std::size_t n) noexcept(false);
1968
1970void* mi_new_n(size_t count, size_t size) noexcept(false);
1971
1973void* mi_new_aligned(std::size_t n, std::align_val_t alignment) noexcept(false);
1974
1976void* mi_new_nothrow(size_t n);
1977
1979void* mi_new_aligned_nothrow(size_t n, size_t alignment);
1980
1982void* mi_new_realloc(void* p, size_t newsize);
1983
1985void* mi_new_reallocn(void* p, size_t newcount, size_t size);
1986
1988void* mi_heap_alloc_new(mi_heap_t* heap, size_t size);
1989
1991void* mi_heap_alloc_new_n(mi_heap_t* heap, size_t count, size_t size);
1992
1994void* mi_theap_alloc_new(mi_theap_t* theap, size_t size);
1995
1997void* mi_theap_alloc_new_n(mi_theap_t* theap, size_t count, size_t size);
1998
2001void* mi_theap_alloc_new_nothrow(mi_theap_t* theap, size_t size);
2002
2010template<class T> struct mi_stl_allocator { }
2011
2013
2120
2234
2305
2486
2689
2731
2759
2827
2925
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:829
size_t block_size
size in bytes of one block
Definition mimalloc-doc.h:827
size_t committed
current committed bytes of this area
Definition mimalloc-doc.h:825
size_t full_block_size
size in bytes of a full block including padding and metadata.
Definition mimalloc-doc.h:828
size_t used
bytes in use by allocated blocks
Definition mimalloc-doc.h:826
void * blocks
start of the area containing heap blocks
Definition mimalloc-doc.h:823
size_t reserved
bytes reserved for this area
Definition mimalloc-doc.h:824
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:839
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:822
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:901
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:1007
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:2010
void mi_thread_done(void)
Uninitialize mimalloc on a thread.
void mi_collect_reduce(size_t target_thread_owned)
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_deferred_free_fun(bool force, unsigned long long heartbeat, void *arg)
Type of deferred free functions.
Definition mimalloc-doc.h:1191
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 ...
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.
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_error_fun(int err, void *arg)
Type of error callback functions.
Definition mimalloc-doc.h:1230
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_free_small_local(void *p)
v3: As mi_free_small(), but the block's page must be owned by the calling thread.
void mi_thread_set_in_threadpool(void)
v3: Communicate that a thread is in a threadpool.
void * mi_wmalloc_small(size_t wsize)
v3: Allocate a small object with its size expressed in machine words.
void mi_output_fun(const char *msg, void *arg)
Type of output functions.
Definition mimalloc-doc.h:1215
void mi_register_output(mi_output_fun *out, void *arg)
Register an output function.
void mi_free_small_local_nonnull(void *p)
As mi_free_small_local(), but p must not be NULL.
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:620
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.
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 probable allocation block size for a given required size.
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:1679
@ mi_option_guarded_min
only used when building with MI_GUARDED: minimal rounded object size for guarded objects (=0)
Definition mimalloc-doc.h:1700
@ mi_option_abandoned_reclaim_on_free
v1,v2: allow to reclaim an abandoned segment on a free (=1)
Definition mimalloc-doc.h:1717
@ mi_option_purge_extend_delay
v1,v2: extend purge delay on each subsequent delay (=1)
Definition mimalloc-doc.h:1718
@ mi_option_allow_thp
allow transparent huge pages? (=1) (on Android =0 by default). Set to 0 to disable THP for the proces...
Definition mimalloc-doc.h:1697
@ mi_option_show_stats
Print statistics on termination.
Definition mimalloc-doc.h:1682
@ mi_option_use_numa_nodes
0 = use all available numa nodes, otherwise use at most N nodes.
Definition mimalloc-doc.h:1712
@ 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:1730
@ mi_option_abandoned_page_purge
v1,v2: immediately purge delayed purges on thread termination
Definition mimalloc-doc.h:1710
@ 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:1708
@ mi_option_eager_commit
v1,v2: eager commit segments? (after eager_commit_delay segments) (enabled by default).
Definition mimalloc-doc.h:1707
@ mi_option_visit_abandoned
v1,v2: allow visiting heap blocks from abandoned threads (=0)
Definition mimalloc-doc.h:1720
@ 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:1702
@ mi_option_os_tag
tag used for OS logging (macOS only for now) (=100)
Definition mimalloc-doc.h:1694
@ 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:1733
@ 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:1732
@ _mi_option_last
Definition mimalloc-doc.h:1735
@ 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:1715
@ 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:1731
@ mi_option_page_commit_on_demand
v3: commit page memory on-demand (=0)
Definition mimalloc-doc.h:1729
@ 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:1704
@ mi_option_verbose
Print verbose messages.
Definition mimalloc-doc.h:1683
@ mi_option_allow_large_os_pages
allow large (2 or 4 MiB) OS pages, implies eager commit.
Definition mimalloc-doc.h:1691
@ mi_option_arena_purge_mult
multiplier for purge_delay for the purging delay for arenas (=10)
Definition mimalloc-doc.h:1716
@ mi_option_target_segments_per_thread
v1,v2: experimental (=0)
Definition mimalloc-doc.h:1721
@ mi_option_generic_collect
collect heaps every N (=10000) generic allocation calls
Definition mimalloc-doc.h:1696
@ 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:1695
@ mi_option_guarded_max
only used when building with MI_GUARDED: maximal rounded object size for guarded objects (=0)
Definition mimalloc-doc.h:1701
@ 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:1692
@ mi_option_reserve_huge_os_pages_at
Reserve N huge OS pages at a specific NUMA node N.
Definition mimalloc-doc.h:1689
@ mi_option_pagemap_commit
v3: commit the full pagemap (to always catch invalid pointer uses) (=0)
Definition mimalloc-doc.h:1728
@ mi_option_max_segment_reclaim
v2: max. percentage of the abandoned segments can be reclaimed per try (=10%)
Definition mimalloc-doc.h:1714
@ mi_option_max_vabits
v3: max user space virtual address bits to consider (=48)
Definition mimalloc-doc.h:1727
@ 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:1693
@ 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:1724
@ mi_option_reserve_huge_os_pages
reserve N huge OS pages (1GiB pages) at startup
Definition mimalloc-doc.h:1688
@ mi_option_page_max_candidates
v3: max candidate pages to consider for allocation (=4)
Definition mimalloc-doc.h:1726
@ mi_option_disallow_os_alloc
1 = do not use OS memory for allocation (but only programmatically reserved arenas)
Definition mimalloc-doc.h:1713
@ 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:1711
@ mi_option_disallow_arena_alloc
1 = do not use arena's for allocation (except if using specific arena id's)
Definition mimalloc-doc.h:1719
@ mi_option_guarded_sample_rate
guard an object in the min/max range about every N requested bytes (=0)
Definition mimalloc-doc.h:1703
@ mi_option_max_errors
issue at most N error messages
Definition mimalloc-doc.h:1684
@ 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:1725
@ mi_option_max_warnings
issue at most N warning messages
Definition mimalloc-doc.h:1685
@ mi_option_show_errors
Print error messages.
Definition mimalloc-doc.h:1681
@ 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:1690
@ mi_option_arena_eager_commit
eager commit arenas? Use 2 to enable just on overcommit systems (=2)
Definition mimalloc-doc.h:1709
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)
Free an object that was allocated aligned.
void mi_free_size_nonnull(void *p, size_t size)
Free a non-NULL pointer that was allocated with a known size.
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)
Corresponds to C23 free_sized.
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)
Free a block that was allocated with a known size.
void * mi_aligned_recalloc(void *p, size_t newcount, size_t size, size_t alignment)
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.
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:1597
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(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.
void mi_pprof_profiler_delete(mi_profiler_t *profiler)
experimental: Delete a built-in profiler created by mi_pprof_profiler_new().
void mi_ufree(void *p, size_t *block_size)
Free p and report its block size, or 0 if p is NULL.
void * mi_ucalloc(size_t count, size_t size, size_t *block_size)
Allocate count zero-initialized elements of size bytes and report the block size.
void * mi_umalloc_aligned(size_t size, size_t alignment, size_t *block_size)
As mi_malloc_aligned(), additionally reporting the block size on success.
void * mi_umalloc_small(size_t size, size_t *block_size)
As mi_malloc_small(), additionally reporting the block size on success.
void * mi_uzalloc_aligned(size_t size, size_t alignment, size_t *block_size)
As mi_zalloc_aligned(), additionally reporting the block size on success.
void * mi_urealloc(void *p, size_t newsize, size_t *block_size_pre, size_t *block_size_post)
Reallocate p to newsize bytes and report the old and new block sizes.
void * mi_umalloc(size_t size, size_t *block_size)
Allocate size bytes and report the block size through block_size.
void * mi_uzalloc_small(size_t size, size_t *block_size)
As mi_zalloc_small(), additionally reporting the block size on success.
size_t version
initialize with `MI_STAT_VERSION (so linking dynamically with a separately compiled mimalloc is safe)
Definition mimalloc-doc.h:1366
size_t size
initialize with sizeof(mi_stats_t) (so linking dynamically with a separately compiled mimalloc is saf...
Definition mimalloc-doc.h:1364
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:1362
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:1103
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:1072
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_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.
mi_theap_t * mi_heap_theap(mi_heap_t *heap)
Return the thread-local theap for the given heap.
void * mi_theap_malloc_aligned(mi_theap_t *theap, size_t size, size_t alignment)
struct mi_theap_s mi_theap_t
Type of thread-local heaps.
Definition mimalloc-doc.h:1771
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.
void * mi_theap_rezalloc_aligned(mi_theap_t *theap, void *p, size_t newsize, size_t alignment)
As mi_rezalloc_aligned(), using a theap belonging to the calling thread.
void * mi_theap_malloc(mi_theap_t *theap, size_t size)
Allocate in a specific theap.
void * mi_theap_calloc(mi_theap_t *theap, size_t count, size_t size)
void * mi_theap_rezalloc(mi_theap_t *theap, void *p, size_t newsize)
As mi_rezalloc(), using a theap belonging to the calling thread.
void * mi_heap_recalloc_aligned_at(mi_heap_t *heap, void *p, size_t newcount, size_t size, size_t alignment, size_t offset)
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.
void * mi_heap_rezalloc_aligned_at(mi_heap_t *heap, void *p, size_t newsize, size_t alignment, size_t offset)
void * mi_recalloc_aligned(void *p, size_t newcount, size_t size, size_t alignment)
void * mi_rezalloc_aligned(void *p, size_t newsize, size_t alignment)
void * mi_heap_rezalloc_aligned(mi_heap_t *heap, void *p, size_t newsize, size_t alignment)
void * mi_rezalloc_aligned_at(void *p, size_t newsize, size_t alignment, size_t offset)
void * mi_heap_recalloc_aligned(mi_heap_t *heap, void *p, size_t newcount, size_t size, size_t alignment)
void * mi_heap_rezalloc(mi_heap_t *heap, void *p, size_t newsize)
void * mi_recalloc_aligned_at(void *p, size_t newcount, size_t size, size_t alignment, size_t offset)
void * mi_heap_recalloc(mi_heap_t *heap, void *p, size_t newcount, size_t size)
void * mi_rezalloc(void *p, size_t newsize)