8 #error "documentation file only!" 109 void*
mi_calloc(
size_t count,
size_t size);
135 void*
mi_recalloc(
void* p,
size_t count,
size_t size);
150 void*
mi_expand(
void* p,
size_t newsize);
172 void*
mi_reallocn(
void* p,
size_t count,
size_t size);
226 char*
mi_realpath(
const char* fname,
char* resolved_name);
240 #define MI_SMALL_SIZE_MAX (128*sizeof(void*)) 506 #define mi_malloc_tp(tp) ((tp*)mi_malloc(sizeof(tp))) 509 #define mi_zalloc_tp(tp) ((tp*)mi_zalloc(sizeof(tp))) 512 #define mi_calloc_tp(tp,count) ((tp*)mi_calloc(count,sizeof(tp))) 515 #define mi_mallocn_tp(tp,count) ((tp*)mi_mallocn(count,sizeof(tp))) 518 #define mi_reallocn_tp(p,tp,count) ((tp*)mi_reallocn(p,count,sizeof(tp))) 521 #define mi_heap_malloc_tp(hp,tp) ((tp*)mi_heap_malloc(hp,sizeof(tp))) 524 #define mi_heap_zalloc_tp(hp,tp) ((tp*)mi_heap_zalloc(hp,sizeof(tp))) 527 #define mi_heap_calloc_tp(hp,tp,count) ((tp*)mi_heap_calloc(hp,count,sizeof(tp))) 530 #define mi_heap_mallocn_tp(hp,tp,count) ((tp*)mi_heap_mallocn(hp,count,sizeof(tp))) 533 #define mi_heap_reallocn_tp(hp,p,tp,count) ((tp*)mi_heap_reallocn(p,count,sizeof(tp))) 572 typedef struct mi_heap_area_s {
611 typedef enum mi_option_e {
647 void*
mi_recalloc(
void* p,
size_t count,
size_t size);
666 void*
mi_new(std::size_t n) noexcept(
false);
669 void*
mi_new_aligned(std::size_t n, std::align_val_t alignment) noexcept(
false);
void mi_stats_print(FILE *out)
Print statistics.
void mi_option_enable_default(mi_option_t option, bool enable)
size_t mi_usable_size(void *p)
Return the available bytes in a memory block.
+
Experimental.
Definition: mimalloc-doc.h:624
void * mi_reallocn(void *p, size_t count, size_t size)
Re-allocate memory to count elements of size bytes.
void * mi_malloc_aligned(size_t size, size_t alignment)
Allocate size bytes aligned by alignment.
void * mi_heap_realloc_aligned(mi_heap_t *heap, void *p, size_t newsize, size_t alignment)
@@ -112,17 +113,18 @@ $(document).ready(function(){initNavTree('mimalloc-doc_8h_source.html','');});
void * mi_mallocn(size_t count, size_t size)
Allocate count elements of size bytes.
size_t mi_malloc_size(const void *p)
void mi_thread_done()
Uninitialize mimalloc on a thread.
-
Reset segment memory when a segment is cached.
Definition: mimalloc-doc.h:613
+
Reset segment memory when a segment is cached.
Definition: mimalloc-doc.h:622
int mi_posix_memalign(void **p, size_t alignment, size_t size)
-
Commit segments in large pools.
Definition: mimalloc-doc.h:614
void mi_option_set_default(mi_option_t option, long value)
-
void * mi_new_aligned(std::size_t n, std::align_val_t alignment) noexcept(false)
Only defined in C++ compilation; raise std::bad_alloc exception on failure.
+
void * mi_new_aligned(std::size_t n, std::align_val_t alignment) noexcept(false)
raise std::bad_alloc exception on failure.
+
Eagerly commit segments (4MiB) (enabled by default).
Definition: mimalloc-doc.h:618
void * mi_heap_zalloc(mi_heap_t *heap, size_t size)
Allocate zero-initialized in a specific heap.
void mi_option_set(mi_option_t option, long value)
void mi_register_deferred_free(mi_deferred_free_fun *deferred_free)
Register a deferred free function.
+
Eagerly commit large (256MiB) memory regions (enabled by default except on Windows)
Definition: mimalloc-doc.h:619
void mi_thread_stats_print(FILE *out)
Print out heap statistics for this thread.
-
Definition: mimalloc-doc.h:618
+
Definition: mimalloc-doc.h:625
void * mi_realloc_aligned_at(void *p, size_t newsize, size_t alignment, size_t offset)
void * blocks
start of the area containing heap blocks
Definition: mimalloc-doc.h:573
void * mi_realloc_aligned(void *p, size_t newsize, size_t alignment)
@@ -140,7 +142,7 @@ $(document).ready(function(){initNavTree('mimalloc-doc_8h_source.html','');});
void * mi_zalloc(size_t size)
Allocate zero-initialized size bytes.
void mi_thread_init()
Initialize mimalloc on a thread.
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_new(std::size_t n) noexcept(false)
Only defined in C++ compilation; raise std::bad_alloc exception on failure.
+
void * mi_new(std::size_t n) noexcept(false)
raise std::bad_alloc exception on failure.
void * mi_heap_calloc_aligned(mi_heap_t *heap, size_t count, size_t size, size_t alignment)
size_t block_size
size in bytes of one block
Definition: mimalloc-doc.h:577
void * mi_reallocarray(void *p, size_t count, size_t size)
@@ -148,18 +150,21 @@ $(document).ready(function(){initNavTree('mimalloc-doc_8h_source.html','');});
void * mi_realloc(void *p, size_t newsize)
Re-allocate memory to newsize bytes.
void * mi_heap_reallocf(mi_heap_t *heap, void *p, size_t newsize)
void mi_free_size_aligned(void *p, size_t size, size_t alignment)
-
Reset page memory when it becomes free.
Definition: mimalloc-doc.h:612
+
Reset page memory when it becomes free.
Definition: mimalloc-doc.h:621
bool mi_heap_visit_blocks(const mi_heap_t *heap, bool visit_all_blocks, mi_block_visit_fun *visitor, void *arg)
Visit all areas and blocks in a heap.
void * mi_malloc(size_t size)
Allocate size bytes.
bool mi_option_enabled(mi_option_t option)
+
Experimental.
Definition: mimalloc-doc.h:623
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.
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:587
void * mi_heap_malloc_aligned_at(mi_heap_t *heap, size_t size, size_t alignment, size_t offset)
char * mi_realpath(const char *fname, char *resolved_name)
Resolve a file path name.
-
Print error messages to stderr.
Definition: mimalloc-doc.h:616
+
Print error messages to stderr.
Definition: mimalloc-doc.h:614
void * mi_memalign(size_t alignment, size_t size)
+
void * mi_new_aligned_nothrow(size_t n, size_t alignment)
return NULL on failure.
+
void * mi_new_nothrow(size_t n)
return NULL on failure.
bool mi_heap_contains_block(mi_heap_t *heap, const void *p)
Does a heap contain a pointer to a previously allocated block?
-
Print verbose messages to stderr.
Definition: mimalloc-doc.h:617
+
Print verbose messages to stderr.
Definition: mimalloc-doc.h:615
void * mi_zalloc_aligned_at(size_t size, size_t alignment, size_t offset)
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_heap_delete(mi_heap_t *heap)
Delete a previously allocated heap.
@@ -169,7 +174,7 @@ $(document).ready(function(){initNavTree('mimalloc-doc_8h_source.html','');});
size_t mi_good_size(size_t size)
Return the used allocation size.
void * mi_heap_mallocn(mi_heap_t *heap, size_t count, size_t size)
Allocate count elements in a specific heap.
An area of heap space contains blocks of a single size.
Definition: mimalloc-doc.h:572
-
Print statistics to stderr when the program is done.
Definition: mimalloc-doc.h:615
+
Print statistics to stderr when the program is done.
Definition: mimalloc-doc.h:613
void * mi_zalloc_aligned(size_t size, size_t alignment)
size_t reserved
bytes reserved for this area
Definition: mimalloc-doc.h:574
struct mi_heap_s mi_heap_t
Type of first-class heaps.
Definition: mimalloc-doc.h:407
@@ -179,6 +184,8 @@ $(document).ready(function(){initNavTree('mimalloc-doc_8h_source.html','');});
void mi_collect(bool force)
Eagerly free memory.
void mi_heap_destroy(mi_heap_t *heap)
Destroy a heap, freeing all its still allocated blocks.
void * mi_calloc_aligned_at(size_t count, size_t size, size_t alignment, size_t offset)
+
Use large OS pages if possible.
Definition: mimalloc-doc.h:620
+
Experimental.
Definition: mimalloc-doc.h:617
void mi_stats_reset()
Reset statistics.
void * mi_heap_reallocn(mi_heap_t *heap, void *p, size_t count, size_t size)
void * mi_heap_realloc(mi_heap_t *heap, void *p, size_t newsize)
diff --git a/docs/navtreeindex0.js b/docs/navtreeindex0.js
index 2cc6d486..f026a1ff 100644
--- a/docs/navtreeindex0.js
+++ b/docs/navtreeindex0.js
@@ -89,28 +89,35 @@ var NAVTREEINDEX0 =
"group__options.html#gacebe3f6d91b4a50b54eb84e2a1da1b30":[4,6,3],
"group__options.html#gaf84921c32375e25754dc2ee6a911fa60":[4,6,5],
"group__options.html#gafebf7ed116adb38ae5218bc3ce06884c":[4,6,0],
-"group__options.html#ggafebf7ed116adb38ae5218bc3ce06884ca0957ef73b2550764b4840edf48422fda":[4,6,0,3],
-"group__options.html#ggafebf7ed116adb38ae5218bc3ce06884ca1d7948dd9565c26d411e6dbdf549be79":[4,6,0,2],
-"group__options.html#ggafebf7ed116adb38ae5218bc3ce06884ca5b4357b74be0d87568036c32eb1a2e4a":[4,6,0,6],
-"group__options.html#ggafebf7ed116adb38ae5218bc3ce06884ca7c8b7bf5281c581bad64f5daa6442777":[4,6,0,5],
-"group__options.html#ggafebf7ed116adb38ae5218bc3ce06884cac2157a0cb79cd996c1db7d9f6a090c07":[4,6,0,1],
-"group__options.html#ggafebf7ed116adb38ae5218bc3ce06884cada854dd272c66342f18a93ee254a2968":[4,6,0,0],
-"group__options.html#ggafebf7ed116adb38ae5218bc3ce06884cafbf4822e5c00732c5984b32a032837f0":[4,6,0,4],
+"group__options.html#ggafebf7ed116adb38ae5218bc3ce06884ca083ee20765063fc6d727e11d33cf378f":[4,6,0,3],
+"group__options.html#ggafebf7ed116adb38ae5218bc3ce06884ca0957ef73b2550764b4840edf48422fda":[4,6,0,0],
+"group__options.html#ggafebf7ed116adb38ae5218bc3ce06884ca1e8de72c93da7ff22d91e1e27b52ac2b":[4,6,0,4],
+"group__options.html#ggafebf7ed116adb38ae5218bc3ce06884ca32ce97ece29f69e82579679cf8a307ad":[4,6,0,5],
+"group__options.html#ggafebf7ed116adb38ae5218bc3ce06884ca4192d491200d0055df0554d4cf65054e":[4,6,0,6],
+"group__options.html#ggafebf7ed116adb38ae5218bc3ce06884ca5b4357b74be0d87568036c32eb1a2e4a":[4,6,0,11],
+"group__options.html#ggafebf7ed116adb38ae5218bc3ce06884ca7c8b7bf5281c581bad64f5daa6442777":[4,6,0,2],
+"group__options.html#ggafebf7ed116adb38ae5218bc3ce06884cab3a837b5ceee250e14e051dbee2a441b":[4,6,0,10],
+"group__options.html#ggafebf7ed116adb38ae5218bc3ce06884cac2157a0cb79cd996c1db7d9f6a090c07":[4,6,0,8],
+"group__options.html#ggafebf7ed116adb38ae5218bc3ce06884cac81ee965b130fa81238913a3c239d536":[4,6,0,9],
+"group__options.html#ggafebf7ed116adb38ae5218bc3ce06884cada854dd272c66342f18a93ee254a2968":[4,6,0,7],
+"group__options.html#ggafebf7ed116adb38ae5218bc3ce06884cafbf4822e5c00732c5984b32a032837f0":[4,6,0,1],
"group__posix.html":[4,7],
"group__posix.html#ga06d07cf357bbac5c73ba5d0c0c421e17":[4,7,7],
"group__posix.html#ga0d28d5cf61e6bfbb18c63092939fe5c9":[4,7,3],
"group__posix.html#ga1326d2e4388630b5f81ca7206318b8e5":[4,7,1],
"group__posix.html#ga4531c9e775bb3ae12db57c1ba8a5d7de":[4,7,6],
-"group__posix.html#ga48fad8648a2f1dab9c87ea9448a52088":[4,7,13],
+"group__posix.html#ga48fad8648a2f1dab9c87ea9448a52088":[4,7,15],
"group__posix.html#ga705dc7a64bffacfeeb0141501a5c35d7":[4,7,2],
"group__posix.html#ga72e9d7ffb5fe94d69bc722c8506e27bc":[4,7,5],
-"group__posix.html#ga73baaf5951f5165ba0763d0c06b6a93b":[4,7,14],
+"group__posix.html#ga73baaf5951f5165ba0763d0c06b6a93b":[4,7,16],
"group__posix.html#gaab7fa71ea93b96873f5d9883db57d40e":[4,7,8],
"group__posix.html#gaad048a9fce3d02c5909cd05c6ec24545":[4,7,9],
-"group__posix.html#gacff84f226ba9feb2031b8992e5579447":[4,7,11],
+"group__posix.html#gab5e29558926d934c3f1cae8c815f942c":[4,7,11],
+"group__posix.html#gacff84f226ba9feb2031b8992e5579447":[4,7,13],
"group__posix.html#gad5a69c8fea96aa2b7a7c818c2130090a":[4,7,0],
"group__posix.html#gae01389eedab8d67341ff52e2aad80ebb":[4,7,4],
-"group__posix.html#gaeb325c39b887d3b90d85d1eb1712fb1e":[4,7,12],
+"group__posix.html#gaeaded64eda71ed6b1d569d3e723abc4a":[4,7,12],
+"group__posix.html#gaeb325c39b887d3b90d85d1eb1712fb1e":[4,7,14],
"group__posix.html#gaef2c2bdb4f70857902d3c8903ac095f3":[4,7,10],
"group__typed.html":[4,4],
"group__typed.html#ga0619a62c5fd886f1016030abe91f0557":[4,4,6],
diff --git a/docs/overrides.html b/docs/overrides.html
index 2360a936..2833f4f9 100644
--- a/docs/overrides.html
+++ b/docs/overrides.html
@@ -105,17 +105,22 @@ $(document).ready(function(){initNavTree('overrides.html','');});
Overriding the standard malloc
can be done either dynamically or statically.
Dynamic override
This is the recommended way to override the standard malloc interface.
-
Unix, BSD, macOS
+
Linux, BSD
On these systems we preload the mimalloc shared library so all calls to the standard malloc
interface are resolved to the mimalloc library.
-
You can set extra environment variables to check that mimalloc is running, like:
env MIMALLOC_VERBOSE=1 LD_PRELOAD=/usr/lib/libmimalloc.so myprogram
or run with the debug version to get detailed statistics:
env MIMALLOC_SHOW_STATS=1 LD_PRELOAD=/usr/lib/libmimalloc-debug.so myprogram
Windows
-
On Windows you need to link your program explicitly with the mimalloc DLL, and use the C-runtime library as a DLL (the /MD
or /MDd
switch). To ensure the mimalloc DLL gets loaded it is easiest to insert some call to the mimalloc API in the main
function, like mi_version()
.
+
You can set extra environment variables to check that mimalloc is running, like:
env MIMALLOC_VERBOSE=1 LD_PRELOAD=/usr/lib/libmimalloc.so myprogram
or run with the debug version to get detailed statistics:
env MIMALLOC_SHOW_STATS=1 LD_PRELOAD=/usr/lib/libmimalloc-debug.so myprogram
MacOS
+
On macOS we can also preload the mimalloc shared library so all calls to the standard malloc
interface are resolved to the mimalloc library.
+
+env DYLD_FORCE_FLAT_NAMESPACE=1 DYLD_INSERT_LIBRARIES=/usr/lib/libmimalloc.dylib myprogram
+
+
Note that certain security restrictions may apply when doing this from the shell.
+
Note: unfortunately, at this time, dynamic overriding on macOS seems broken but it is actively worked on to fix this (see issue #50
).
+
Windows
+
On Windows you need to link your program explicitly with the mimalloc DLL, and use the C-runtime library as a DLL (the /MD
or /MDd
switch). To ensure the mimalloc DLL gets loaded it is easiest to insert some call to the mimalloc API in the main
function, like mi_version()
(or use the /INCLUDE:mi_version
switch on the linker)
Due to the way mimalloc intercepts the standard malloc at runtime, it is best to link to the mimalloc import library first on the command line so it gets loaded right after the universal C runtime DLL (ucrtbase
). See the mimalloc-override-test
project for an example.
+
Note: the current overriding on Windows works for most programs but some programs still have trouble – the dev-exp
branch contains a newer way of overriding that is more robust; try this out if you experience troubles.
Static override
On Unix systems, you can also statically link with mimalloc to override the standard malloc interface. The recommended way is to link the final program with the mimalloc single object file (mimalloc-override.o
). We use an object file instead of a library file as linkers give preference to that over archives to resolve symbols. To ensure that the standard malloc interface resolves to the mimalloc library, link it as the first object file. For example:
gcc -o myprogram mimalloc-override.o myfile1.c ...
List of Overrides:
diff --git a/docs/search/all_6.js b/docs/search/all_6.js
index cb826ae7..58ffa7e6 100644
--- a/docs/search/all_6.js
+++ b/docs/search/all_6.js
@@ -63,13 +63,20 @@ var searchData=
['mi_5fmemalign',['mi_memalign',['../group__posix.html#gaab7fa71ea93b96873f5d9883db57d40e',1,'mimalloc-doc.h']]],
['mi_5fnew',['mi_new',['../group__posix.html#gaad048a9fce3d02c5909cd05c6ec24545',1,'mimalloc-doc.h']]],
['mi_5fnew_5faligned',['mi_new_aligned',['../group__posix.html#gaef2c2bdb4f70857902d3c8903ac095f3',1,'mimalloc-doc.h']]],
+ ['mi_5fnew_5faligned_5fnothrow',['mi_new_aligned_nothrow',['../group__posix.html#gab5e29558926d934c3f1cae8c815f942c',1,'mimalloc-doc.h']]],
+ ['mi_5fnew_5fnothrow',['mi_new_nothrow',['../group__posix.html#gaeaded64eda71ed6b1d569d3e723abc4a',1,'mimalloc-doc.h']]],
['mi_5foption_5fcache_5freset',['mi_option_cache_reset',['../group__options.html#ggafebf7ed116adb38ae5218bc3ce06884cac2157a0cb79cd996c1db7d9f6a090c07',1,'mimalloc-doc.h']]],
+ ['mi_5foption_5feager_5fcommit',['mi_option_eager_commit',['../group__options.html#ggafebf7ed116adb38ae5218bc3ce06884ca1e8de72c93da7ff22d91e1e27b52ac2b',1,'mimalloc-doc.h']]],
+ ['mi_5foption_5feager_5fregion_5fcommit',['mi_option_eager_region_commit',['../group__options.html#ggafebf7ed116adb38ae5218bc3ce06884ca32ce97ece29f69e82579679cf8a307ad',1,'mimalloc-doc.h']]],
['mi_5foption_5fenable',['mi_option_enable',['../group__options.html#ga6d45a20a3131f18bc351b69763b38ce4',1,'mimalloc-doc.h']]],
['mi_5foption_5fenable_5fdefault',['mi_option_enable_default',['../group__options.html#ga37988264b915a7db92530cc02d5494cb',1,'mimalloc-doc.h']]],
['mi_5foption_5fenabled',['mi_option_enabled',['../group__options.html#gacebe3f6d91b4a50b54eb84e2a1da1b30',1,'mimalloc-doc.h']]],
['mi_5foption_5fget',['mi_option_get',['../group__options.html#ga7e8af195cc81d3fa64ccf2662caa565a',1,'mimalloc-doc.h']]],
+ ['mi_5foption_5flarge_5fos_5fpages',['mi_option_large_os_pages',['../group__options.html#ggafebf7ed116adb38ae5218bc3ce06884ca4192d491200d0055df0554d4cf65054e',1,'mimalloc-doc.h']]],
['mi_5foption_5fpage_5freset',['mi_option_page_reset',['../group__options.html#ggafebf7ed116adb38ae5218bc3ce06884cada854dd272c66342f18a93ee254a2968',1,'mimalloc-doc.h']]],
- ['mi_5foption_5fpool_5fcommit',['mi_option_pool_commit',['../group__options.html#ggafebf7ed116adb38ae5218bc3ce06884ca1d7948dd9565c26d411e6dbdf549be79',1,'mimalloc-doc.h']]],
+ ['mi_5foption_5freset_5fdecommits',['mi_option_reset_decommits',['../group__options.html#ggafebf7ed116adb38ae5218bc3ce06884cac81ee965b130fa81238913a3c239d536',1,'mimalloc-doc.h']]],
+ ['mi_5foption_5freset_5fdiscards',['mi_option_reset_discards',['../group__options.html#ggafebf7ed116adb38ae5218bc3ce06884cab3a837b5ceee250e14e051dbee2a441b',1,'mimalloc-doc.h']]],
+ ['mi_5foption_5fsecure',['mi_option_secure',['../group__options.html#ggafebf7ed116adb38ae5218bc3ce06884ca083ee20765063fc6d727e11d33cf378f',1,'mimalloc-doc.h']]],
['mi_5foption_5fset',['mi_option_set',['../group__options.html#gaf84921c32375e25754dc2ee6a911fa60',1,'mimalloc-doc.h']]],
['mi_5foption_5fset_5fdefault',['mi_option_set_default',['../group__options.html#ga7ef623e440e6e5545cb08c94e71e4b90',1,'mimalloc-doc.h']]],
['mi_5foption_5fshow_5ferrors',['mi_option_show_errors',['../group__options.html#ggafebf7ed116adb38ae5218bc3ce06884cafbf4822e5c00732c5984b32a032837f0',1,'mimalloc-doc.h']]],
diff --git a/docs/search/enumvalues_1.js b/docs/search/enumvalues_1.js
index 2dacbec8..b9c9b6f6 100644
--- a/docs/search/enumvalues_1.js
+++ b/docs/search/enumvalues_1.js
@@ -1,8 +1,13 @@
var searchData=
[
['mi_5foption_5fcache_5freset',['mi_option_cache_reset',['../group__options.html#ggafebf7ed116adb38ae5218bc3ce06884cac2157a0cb79cd996c1db7d9f6a090c07',1,'mimalloc-doc.h']]],
+ ['mi_5foption_5feager_5fcommit',['mi_option_eager_commit',['../group__options.html#ggafebf7ed116adb38ae5218bc3ce06884ca1e8de72c93da7ff22d91e1e27b52ac2b',1,'mimalloc-doc.h']]],
+ ['mi_5foption_5feager_5fregion_5fcommit',['mi_option_eager_region_commit',['../group__options.html#ggafebf7ed116adb38ae5218bc3ce06884ca32ce97ece29f69e82579679cf8a307ad',1,'mimalloc-doc.h']]],
+ ['mi_5foption_5flarge_5fos_5fpages',['mi_option_large_os_pages',['../group__options.html#ggafebf7ed116adb38ae5218bc3ce06884ca4192d491200d0055df0554d4cf65054e',1,'mimalloc-doc.h']]],
['mi_5foption_5fpage_5freset',['mi_option_page_reset',['../group__options.html#ggafebf7ed116adb38ae5218bc3ce06884cada854dd272c66342f18a93ee254a2968',1,'mimalloc-doc.h']]],
- ['mi_5foption_5fpool_5fcommit',['mi_option_pool_commit',['../group__options.html#ggafebf7ed116adb38ae5218bc3ce06884ca1d7948dd9565c26d411e6dbdf549be79',1,'mimalloc-doc.h']]],
+ ['mi_5foption_5freset_5fdecommits',['mi_option_reset_decommits',['../group__options.html#ggafebf7ed116adb38ae5218bc3ce06884cac81ee965b130fa81238913a3c239d536',1,'mimalloc-doc.h']]],
+ ['mi_5foption_5freset_5fdiscards',['mi_option_reset_discards',['../group__options.html#ggafebf7ed116adb38ae5218bc3ce06884cab3a837b5ceee250e14e051dbee2a441b',1,'mimalloc-doc.h']]],
+ ['mi_5foption_5fsecure',['mi_option_secure',['../group__options.html#ggafebf7ed116adb38ae5218bc3ce06884ca083ee20765063fc6d727e11d33cf378f',1,'mimalloc-doc.h']]],
['mi_5foption_5fshow_5ferrors',['mi_option_show_errors',['../group__options.html#ggafebf7ed116adb38ae5218bc3ce06884cafbf4822e5c00732c5984b32a032837f0',1,'mimalloc-doc.h']]],
['mi_5foption_5fshow_5fstats',['mi_option_show_stats',['../group__options.html#ggafebf7ed116adb38ae5218bc3ce06884ca0957ef73b2550764b4840edf48422fda',1,'mimalloc-doc.h']]],
['mi_5foption_5fverbose',['mi_option_verbose',['../group__options.html#ggafebf7ed116adb38ae5218bc3ce06884ca7c8b7bf5281c581bad64f5daa6442777',1,'mimalloc-doc.h']]]
diff --git a/docs/search/functions_0.js b/docs/search/functions_0.js
index 7a48746a..2c169f9a 100644
--- a/docs/search/functions_0.js
+++ b/docs/search/functions_0.js
@@ -51,6 +51,8 @@ var searchData=
['mi_5fmemalign',['mi_memalign',['../group__posix.html#gaab7fa71ea93b96873f5d9883db57d40e',1,'mimalloc-doc.h']]],
['mi_5fnew',['mi_new',['../group__posix.html#gaad048a9fce3d02c5909cd05c6ec24545',1,'mimalloc-doc.h']]],
['mi_5fnew_5faligned',['mi_new_aligned',['../group__posix.html#gaef2c2bdb4f70857902d3c8903ac095f3',1,'mimalloc-doc.h']]],
+ ['mi_5fnew_5faligned_5fnothrow',['mi_new_aligned_nothrow',['../group__posix.html#gab5e29558926d934c3f1cae8c815f942c',1,'mimalloc-doc.h']]],
+ ['mi_5fnew_5fnothrow',['mi_new_nothrow',['../group__posix.html#gaeaded64eda71ed6b1d569d3e723abc4a',1,'mimalloc-doc.h']]],
['mi_5foption_5fenable',['mi_option_enable',['../group__options.html#ga6d45a20a3131f18bc351b69763b38ce4',1,'mimalloc-doc.h']]],
['mi_5foption_5fenable_5fdefault',['mi_option_enable_default',['../group__options.html#ga37988264b915a7db92530cc02d5494cb',1,'mimalloc-doc.h']]],
['mi_5foption_5fenabled',['mi_option_enabled',['../group__options.html#gacebe3f6d91b4a50b54eb84e2a1da1b30',1,'mimalloc-doc.h']]],
diff --git a/docs/using.html b/docs/using.html
index 9b7305b0..04e180ef 100644
--- a/docs/using.html
+++ b/docs/using.html
@@ -104,7 +104,16 @@ $(document).ready(function(){initNavTree('using.html','');});
The preferred usage is including <mimalloc.h>
, linking with the shared- or static library, and using the mi_malloc
API exclusively for allocation. For example,
gcc -o myprogram -lmimalloc myfile.c
mimalloc uses only safe OS calls (mmap
and VirtualAlloc
) and can co-exist with other allocators linked to the same program. If you use cmake
, you can simply use:
find_package(mimalloc 1.0 REQUIRED)
in your CMakeLists.txt
to find a locally installed mimalloc. Then use either:
target_link_libraries(myapp PUBLIC mimalloc)
to link with the shared (dynamic) library, or:
target_link_libraries(myapp PUBLIC mimalloc-static)
to link with the static library. See test\CMakeLists.txt
for an example.
You can pass environment variables to print verbose messages (MIMALLOC_VERBOSE=1
) and statistics (MIMALLOC_SHOW_STATS=1
) (in the debug version):
> env MIMALLOC_SHOW_STATS=1 ./cfrac 175451865205073170563711388363
175451865205073170563711388363 = 374456281610909315237213 * 468551
heap stats: peak total freed unit
normal 2: 16.4 kb 17.5 mb 17.5 mb 16 b ok
normal 3: 16.3 kb 15.2 mb 15.2 mb 24 b ok
normal 4: 64 b 4.6 kb 4.6 kb 32 b ok
normal 5: 80 b 118.4 kb 118.4 kb 40 b ok
normal 6: 48 b 48 b 48 b 48 b ok
normal 17: 960 b 960 b 960 b 320 b ok
heap stats: peak total freed unit
normal: 33.9 kb 32.8 mb 32.8 mb 1 b ok
huge: 0 b 0 b 0 b 1 b ok
total: 33.9 kb 32.8 mb 32.8 mb 1 b ok
malloc requested: 32.8 mb
committed: 58.2 kb 58.2 kb 58.2 kb 1 b ok
reserved: 2.0 mb 2.0 mb 2.0 mb 1 b ok
reset: 0 b 0 b 0 b 1 b ok
segments: 1 1 1
-abandoned: 0
pages: 6 6 6
-abandoned: 0
mmaps: 3
mmap fast: 0
mmap slow: 1
threads: 0
elapsed: 2.022s
process: user: 1.781s, system: 0.016s, faults: 756, reclaims: 0, rss: 2.7 mb
The above model of using the mi_
prefixed API is not always possible though in existing programs that already use the standard malloc interface, and another option is to override the standard malloc interface completely and redirect all calls to the mimalloc library instead.
-
See Overriding Malloc for more info.
+
See Overriding Malloc for more info.
+
Environment Options
+
You can set further options either programmatically (using mi_option_set
), or via environment variables.
+
+MIMALLOC_SHOW_STATS=1
: show statistics when the program terminates.
+MIMALLOC_VERBOSE=1
: show verbose messages.
+MIMALLOC_SHOW_ERRORS=1
: show error and warning messages.
+MIMALLOC_LARGE_OS_PAGES=1
: use large OS pages when available; for some workloads this can significantly improve performance. Use MIMALLOC_VERBOSE
to check if the large OS pages are enabled – usually one needs to explicitly allow large OS pages (as on Windows and Linux).
+MIMALLOC_EAGER_REGION_COMMIT=1
: on Windows, commit large (256MiB) regions eagerly. On Windows, these regions show in the working set even though usually just a small part is committed to physical memory. This is why it turned off by default on Windows as it looks not good in the task manager. However, in reality it is always better to turn it on as it improves performance and has no other drawbacks.
+
diff --git a/readme.md b/readme.md
index 8ff19deb..c2efcc19 100644
--- a/readme.md
+++ b/readme.md
@@ -54,6 +54,10 @@ You can read more on the design of _mimalloc_ in the [technical report](https://
Enjoy!
+### Releases
+
+* 2019-08-10, `v1.0.6`: pre-release 6: various performance improvements.
+
# Building
## Windows
@@ -174,7 +178,24 @@ though in existing programs that already use the standard malloc interface,
and another option is to override the standard malloc interface
completely and redirect all calls to the _mimalloc_ library instead.
+## Environment Options
+You can set further options either programmatically (using [`mi_option_set`](https://microsoft.github.io/mimalloc/group__options.html)),
+or via environment variables.
+
+- `MIMALLOC_SHOW_STATS=1`: show statistics when the program terminates.
+- `MIMALLOC_VERBOSE=1`: show verbose messages.
+- `MIMALLOC_SHOW_ERRORS=1`: show error and warning messages.
+- `MIMALLOC_LARGE_OS_PAGES=1`: use large OS pages when available; for some workloads this can significantly
+ improve performance. Use `MIMALLOC_VERBOSE` to check if the large OS pages are enabled -- usually one needs
+ to explicitly allow large OS pages (as on [Windows][windows-huge] and [Linux][linux-huge]).
+- `MIMALLOC_EAGER_REGION_COMMIT=1`: on Windows, commit large (256MiB) regions eagerly. On Windows, these regions
+ show in the working set even though usually just a small part is committed to physical memory. This is why it
+ turned off by default on Windows as it looks not good in the task manager. However, in reality it is always better
+ to turn it on as it improves performance and has no other drawbacks.
+
+[linux-huge]: https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/5/html/tuning_and_optimizing_red_hat_enterprise_linux_for_oracle_9i_and_10g_databases/sect-oracle_9i_and_10g_tuning_guide-large_memory_optimization_big_pages_and_huge_pages-configuring_huge_pages_in_red_hat_enterprise_linux_4_or_5
+[windows-huge]: https://docs.microsoft.com/en-us/sql/database-engine/configure-windows/enable-the-lock-pages-in-memory-option-windows?view=sql-server-2017
# Overriding Malloc
@@ -182,19 +203,15 @@ Overriding the standard `malloc` can be done either _dynamically_ or _statically
## Dynamic override
-This is the recommended way to override the standard malloc interface.
+This is the recommended way to override the standard malloc interface.
-### Unix, BSD, macOS
+### Linux, BSD
On these systems we preload the mimalloc shared
library so all calls to the standard `malloc` interface are
resolved to the _mimalloc_ library.
-- `env LD_PRELOAD=/usr/lib/libmimalloc.so myprogram` (on Linux, BSD, etc.)
-- `env DYLD_INSERT_LIBRARIES=/usr/lib/libmimalloc.dylib myprogram` (On macOS)
-
- Note certain security restrictions may apply when doing this from
- the [shell](https://stackoverflow.com/questions/43941322/dyld-insert-libraries-ignored-when-calling-application-through-bash).
+- `env LD_PRELOAD=/usr/lib/libmimalloc.so myprogram`
You can set extra environment variables to check that mimalloc is running,
like:
@@ -206,18 +223,37 @@ or run with the debug version to get detailed statistics:
env MIMALLOC_SHOW_STATS=1 LD_PRELOAD=/usr/lib/libmimalloc-debug.so myprogram
```
+### MacOS
+
+On macOS we can also preload the mimalloc shared
+library so all calls to the standard `malloc` interface are
+resolved to the _mimalloc_ library.
+
+- `env DYLD_FORCE_FLAT_NAMESPACE=1 DYLD_INSERT_LIBRARIES=/usr/lib/libmimalloc.dylib myprogram`
+
+Note that certain security restrictions may apply when doing this from
+the [shell](https://stackoverflow.com/questions/43941322/dyld-insert-libraries-ignored-when-calling-application-through-bash).
+
+Note: unfortunately, at this time, dynamic overriding on macOS seems broken but it is actively worked on to fix this
+(see issue [`#50`](https://github.com/microsoft/mimalloc/issues/50)).
+
### Windows
On Windows you need to link your program explicitly with the mimalloc
DLL, and use the C-runtime library as a DLL (the `/MD` or `/MDd` switch).
To ensure the mimalloc DLL gets loaded it is easiest to insert some
-call to the mimalloc API in the `main` function, like `mi_version()`.
+call to the mimalloc API in the `main` function, like `mi_version()`
+(or use the `/INCLUDE:mi_version` switch on the linker)
Due to the way mimalloc intercepts the standard malloc at runtime, it is best
to link to the mimalloc import library first on the command line so it gets
loaded right after the universal C runtime DLL (`ucrtbase`). See
the `mimalloc-override-test` project for an example.
+Note: the current overriding on Windows works for most programs but some programs still have
+trouble -- the `dev-exp` branch contains a newer way of overriding that is more
+robust; try this out if you experience troubles.
+
## Static override