diff --git a/doc/mimalloc-doc.h b/doc/mimalloc-doc.h index 3f24a623..67f4fe95 100644 --- a/doc/mimalloc-doc.h +++ b/doc/mimalloc-doc.h @@ -1009,28 +1009,31 @@ 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_PAGE_RESET=1`: reset (or purge) OS pages when not in use. This can reduce - memory fragmentation in long running (server) programs. If performance is impacted, - `MIMALLOC_RESET_DELAY=`_msecs_ can be set higher (100ms by default) to make the page - reset occur less frequently. -- `MIMALLOC_LARGE_OS_PAGES=1`: use large OS pages when available; for some workloads this can significantly +- `MIMALLOC_PAGE_RESET=0`: by default, mimalloc will reset (or purge) OS pages when not in use to signal to the OS + that the underlying physical memory can be reused. This can reduce memory fragmentation in long running (server) + programs. By setting it to `0` no such page resets will be done which can improve performance for programs that are not long + running. As an alternative, the `MIMALLOC_RESET_DELAY=` can be set higher (100ms by default) to make the page + reset occur less frequently instead of turning it off completely. +- `MIMALLOC_LARGE_OS_PAGES=1`: use large OS pages (2MiB) 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]). However, sometimes the OS is very slow to reserve contiguous physical memory for large OS pages so use with care on systems that can have fragmented memory (for that reason, we generally recommend to use `MIMALLOC_RESERVE_HUGE_OS_PAGES` instead when possible). -- `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. -- `MIMALLOC_RESERVE_HUGE_OS_PAGES=N`: where N is the number of 1GiB huge OS pages. This reserves the huge pages at - startup and can give quite a performance improvement on long running workloads. Usually it is better to not use +- `MIMALLOC_RESERVE_HUGE_OS_PAGES=N`: where N is the number of 1GiB _huge_ OS pages. This reserves the huge pages at + startup and sometimes this can give a large (latency) performance improvement on big workloads. + Usually it is better to not use `MIMALLOC_LARGE_OS_PAGES` in combination with this setting. Just like large OS pages, use with care as reserving - contiguous physical memory can take a long time when memory is fragmented. + contiguous physical memory can take a long time when memory is fragmented (but reserving the huge pages is done at + startup only once). Note that we usually need to explicitly enable huge OS pages (as on [Windows][windows-huge] and [Linux][linux-huge])). With huge OS pages, it may be beneficial to set the setting - `MIMALLOC_EAGER_COMMIT_DELAY=N` (with usually `N` as 1) to delay the initial `N` segments + `MIMALLOC_EAGER_COMMIT_DELAY=N` (`N` is 1 by default) to delay the initial `N` segments (of 4MiB) of a thread to not allocate in the huge OS pages; this prevents threads that are short lived and allocate just a little to take up space in the huge OS page area (which cannot be reset). +Use caution when using `fork` in combination with either large or huge OS pages: on a fork, the OS uses copy-on-write +for all pages in the original process including the huge OS pages. When any memory is now written in that area, the +OS will copy the entire 1GiB huge page (or 2MiB large page) which can cause the memory usage to grow in big increments. + [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 @@ -1074,14 +1077,18 @@ resolved to the _mimalloc_ library. 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)). +(Note: macOS support for dynamic overriding is recent, please report any issues.) + ### Windows -Overriding on Windows is robust but requires that you link your program explicitly with +Overriding on Windows is robust and has the +particular advantage to be able to redirect all malloc/free calls that go through +the (dynamic) C runtime allocator, including those from other DLL's or libraries. + +The overriding on Windows requires that you link your program explicitly with the mimalloc DLL and use the C-runtime library as a DLL (using the `/MD` or `/MDd` switch). -Moreover, you need to ensure the `mimalloc-redirect.dll` (or `mimalloc-redirect32.dll`) is available +Also, the `mimalloc-redirect.dll` (or `mimalloc-redirect32.dll`) must be available in the same folder as the main `mimalloc-override.dll` at runtime (as it is a dependency). The redirection DLL ensures that all calls to the C runtime malloc API get redirected to mimalloc (in `mimalloc-override.dll`). @@ -1090,14 +1097,15 @@ To ensure the mimalloc DLL is loaded at run-time 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). See the `mimalloc-override-test` project for an example on how to use this. For best performance on Windows with C++, it -is highly recommended to also override the `new`/`delete` operations (by including +is also recommended to also override the `new`/`delete` operations (by including [`mimalloc-new-delete.h`](https://github.com/microsoft/mimalloc/blob/master/include/mimalloc-new-delete.h) a single(!) source file in your project). The environment variable `MIMALLOC_DISABLE_REDIRECT=1` can be used to disable dynamic overriding at run-time. Use `MIMALLOC_VERBOSE=1` to check if mimalloc was successfully redirected. -(Note: in principle, it is possible to patch existing executables -that are linked with the dynamic C runtime (`ucrtbase.dll`) by just putting the `mimalloc-override.dll` into the import table (and putting `mimalloc-redirect.dll` in the same folder) +(Note: in principle, it is possible to even patch existing executables without any recompilation +if they are linked with the dynamic C runtime (`ucrtbase.dll`) -- just put the `mimalloc-override.dll` +into the import table (and put `mimalloc-redirect.dll` in the same folder) Such patching can be done for example with [CFF Explorer](https://ntcore.com/?page_id=388)). diff --git a/docs/annotated.html b/docs/annotated.html index 5120b803..feba2438 100644 --- a/docs/annotated.html +++ b/docs/annotated.html @@ -37,7 +37,7 @@ Logo
mi-malloc -  1.4 +  1.6
diff --git a/docs/bench.html b/docs/bench.html index 6b289c04..f39fade6 100644 --- a/docs/bench.html +++ b/docs/bench.html @@ -37,7 +37,7 @@ Logo
mi-malloc -  1.4 +  1.6
diff --git a/docs/build.html b/docs/build.html index 755aad88..2bd06f13 100644 --- a/docs/build.html +++ b/docs/build.html @@ -37,7 +37,7 @@ Logo
mi-malloc -  1.4 +  1.6
diff --git a/docs/classes.html b/docs/classes.html index de960fb6..e74a0a24 100644 --- a/docs/classes.html +++ b/docs/classes.html @@ -37,7 +37,7 @@ Logo
mi-malloc -  1.4 +  1.6
diff --git a/docs/environment.html b/docs/environment.html index 1063654e..87d67e4a 100644 --- a/docs/environment.html +++ b/docs/environment.html @@ -37,7 +37,7 @@ Logo
mi-malloc -  1.4 +  1.6
@@ -107,11 +107,11 @@ $(document).ready(function(){initNavTree('environment.html','');});
  • 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_PAGE_RESET=1: reset (or purge) OS pages when not in use. This can reduce memory fragmentation in long running (server) programs. If performance is impacted, MIMALLOC_RESET_DELAY=_msecs_ can be set higher (100ms by default) to make the page reset occur less frequently.
  • -
  • 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). However, sometimes the OS is very slow to reserve contiguous physical memory for large OS pages so use with care on systems that can have fragmented memory (for that reason, we generally recommend to use MIMALLOC_RESERVE_HUGE_OS_PAGES instead when possible).
  • -
  • 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.
  • -
  • MIMALLOC_RESERVE_HUGE_OS_PAGES=N: where N is the number of 1GiB huge OS pages. This reserves the huge pages at startup and can give quite a performance improvement on long running workloads. Usually it is better to not use MIMALLOC_LARGE_OS_PAGES in combination with this setting. Just like large OS pages, use with care as reserving contiguous physical memory can take a long time when memory is fragmented. Note that we usually need to explicitly enable huge OS pages (as on Windows and Linux)). With huge OS pages, it may be beneficial to set the setting MIMALLOC_EAGER_COMMIT_DELAY=N (with usually N as 1) to delay the initial N segments of a thread to not allocate in the huge OS pages; this prevents threads that are short lived and allocate just a little to take up space in the huge OS page area (which cannot be reset).
  • +
  • MIMALLOC_PAGE_RESET=0: by default, mimalloc will reset (or purge) OS pages when not in use to signal to the OS that the underlying physical memory can be reused. This can reduce memory fragmentation in long running (server) programs. By setting it to 0 no such page resets will be done which can improve performance for programs that are not long running. As an alternative, the MIMALLOC_RESET_DELAY=<msecs> can be set higher (100ms by default) to make the page reset occur less frequently instead of turning it off completely.
  • +
  • MIMALLOC_LARGE_OS_PAGES=1: use large OS pages (2MiB) 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). However, sometimes the OS is very slow to reserve contiguous physical memory for large OS pages so use with care on systems that can have fragmented memory (for that reason, we generally recommend to use MIMALLOC_RESERVE_HUGE_OS_PAGES instead when possible).
  • +
  • MIMALLOC_RESERVE_HUGE_OS_PAGES=N: where N is the number of 1GiB huge OS pages. This reserves the huge pages at startup and sometimes this can give a large (latency) performance improvement on big workloads. Usually it is better to not use MIMALLOC_LARGE_OS_PAGES in combination with this setting. Just like large OS pages, use with care as reserving contiguous physical memory can take a long time when memory is fragmented (but reserving the huge pages is done at startup only once). Note that we usually need to explicitly enable huge OS pages (as on Windows and Linux)). With huge OS pages, it may be beneficial to set the setting MIMALLOC_EAGER_COMMIT_DELAY=N (N is 1 by default) to delay the initial N segments (of 4MiB) of a thread to not allocate in the huge OS pages; this prevents threads that are short lived and allocate just a little to take up space in the huge OS page area (which cannot be reset).
  • +

    Use caution when using fork in combination with either large or huge OS pages: on a fork, the OS uses copy-on-write for all pages in the original process including the huge OS pages. When any memory is now written in that area, the OS will copy the entire 1GiB huge page (or 2MiB large page) which can cause the memory usage to grow in big increments.

    diff --git a/docs/functions.html b/docs/functions.html index 43e116ed..62021210 100644 --- a/docs/functions.html +++ b/docs/functions.html @@ -37,7 +37,7 @@ Logo
    mi-malloc -  1.4 +  1.6
    diff --git a/docs/functions_vars.html b/docs/functions_vars.html index 060a18d2..7d41d10e 100644 --- a/docs/functions_vars.html +++ b/docs/functions_vars.html @@ -37,7 +37,7 @@ Logo
    mi-malloc -  1.4 +  1.6
    diff --git a/docs/group__aligned.html b/docs/group__aligned.html index 88c10eb4..a3eaacf0 100644 --- a/docs/group__aligned.html +++ b/docs/group__aligned.html @@ -37,7 +37,7 @@ Logo
    mi-malloc -  1.4 +  1.6
    diff --git a/docs/group__analysis.html b/docs/group__analysis.html index b8d644aa..2487c240 100644 --- a/docs/group__analysis.html +++ b/docs/group__analysis.html @@ -37,7 +37,7 @@ Logo
    mi-malloc -  1.4 +  1.6
    diff --git a/docs/group__cpp.html b/docs/group__cpp.html index caf758a8..88c75888 100644 --- a/docs/group__cpp.html +++ b/docs/group__cpp.html @@ -37,7 +37,7 @@ Logo
    mi-malloc -  1.4 +  1.6
    diff --git a/docs/group__extended.html b/docs/group__extended.html index 9e2a2efc..325d62bf 100644 --- a/docs/group__extended.html +++ b/docs/group__extended.html @@ -37,7 +37,7 @@ Logo
    mi-malloc -  1.4 +  1.6
    diff --git a/docs/group__heap.html b/docs/group__heap.html index 0973279a..1a38c936 100644 --- a/docs/group__heap.html +++ b/docs/group__heap.html @@ -37,7 +37,7 @@ Logo
    mi-malloc -  1.4 +  1.6
    diff --git a/docs/group__malloc.html b/docs/group__malloc.html index bee7b4eb..224c4b08 100644 --- a/docs/group__malloc.html +++ b/docs/group__malloc.html @@ -37,7 +37,7 @@ Logo
    mi-malloc -  1.4 +  1.6
    diff --git a/docs/group__options.html b/docs/group__options.html index 71c7ba24..5e45d7bd 100644 --- a/docs/group__options.html +++ b/docs/group__options.html @@ -37,7 +37,7 @@ Logo
    mi-malloc -  1.4 +  1.6
    diff --git a/docs/group__posix.html b/docs/group__posix.html index 1aea8dc8..fe3a88e1 100644 --- a/docs/group__posix.html +++ b/docs/group__posix.html @@ -37,7 +37,7 @@ Logo
    mi-malloc -  1.4 +  1.6
    diff --git a/docs/group__typed.html b/docs/group__typed.html index cf5ac5d1..5cbfbd6b 100644 --- a/docs/group__typed.html +++ b/docs/group__typed.html @@ -37,7 +37,7 @@ Logo
    mi-malloc -  1.4 +  1.6
    @@ -146,7 +146,7 @@ Macros

    Detailed Description

    Typed allocation macros.

    -

    Macro Definition Documentation

    +

    For example:

    int* p = mi_malloc_tp(int)

    Macro Definition Documentation

    ◆ mi_calloc_tp

    diff --git a/docs/group__zeroinit.html b/docs/group__zeroinit.html index 28983138..3c04a5a6 100644 --- a/docs/group__zeroinit.html +++ b/docs/group__zeroinit.html @@ -37,7 +37,7 @@ Logo
    mi-malloc -  1.4 +  1.6
    diff --git a/docs/index.html b/docs/index.html index 0efc9c09..ce9c983d 100644 --- a/docs/index.html +++ b/docs/index.html @@ -37,7 +37,7 @@ Logo
    mi-malloc -  1.4 +  1.6
    @@ -127,7 +127,9 @@ $(document).ready(function(){initNavTree('index.html','');});
  • Heap Allocation
  • Typed Macros
  • Heap Introspection
  • -
  • Runtime Options
  • +
  • Runtime Options
  • +
  • Posix
  • +
  • C++ wrappers
  • diff --git a/docs/mimalloc-doc_8h_source.html b/docs/mimalloc-doc_8h_source.html index f70ae81f..09c03b9b 100644 --- a/docs/mimalloc-doc_8h_source.html +++ b/docs/mimalloc-doc_8h_source.html @@ -37,7 +37,7 @@ Logo
    mi-malloc -  1.4 +  1.6
    @@ -102,7 +102,7 @@ $(document).ready(function(){initNavTree('mimalloc-doc_8h_source.html','');});
    mimalloc-doc.h
    -
    1 /* ----------------------------------------------------------------------------
    2 Copyright (c) 2018, Microsoft Research, Daan Leijen
    3 This is free software; you can redistribute it and/or modify it under the
    4 terms 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 
    81 
    85 
    89 void mi_free(void* p);
    90 
    95 void* mi_malloc(size_t size);
    96 
    101 void* mi_zalloc(size_t size);
    102 
    112 void* mi_calloc(size_t count, size_t size);
    113 
    126 void* mi_realloc(void* p, size_t newsize);
    127 
    138 void* mi_recalloc(void* p, size_t count, size_t size);
    139 
    153 void* mi_expand(void* p, size_t newsize);
    154 
    164 void* mi_mallocn(size_t count, size_t size);
    165 
    175 void* mi_reallocn(void* p, size_t count, size_t size);
    176 
    193 void* mi_reallocf(void* p, size_t newsize);
    194 
    195 
    204 char* mi_strdup(const char* s);
    205 
    215 char* mi_strndup(const char* s, size_t n);
    216 
    229 char* mi_realpath(const char* fname, char* resolved_name);
    230 
    232 
    233 // ------------------------------------------------------
    234 // Extended functionality
    235 // ------------------------------------------------------
    236 
    240 
    243 #define MI_SMALL_SIZE_MAX (128*sizeof(void*))
    244 
    252 void* mi_malloc_small(size_t size);
    253 
    261 void* mi_zalloc_small(size_t size);
    262 
    277 size_t mi_usable_size(void* p);
    278 
    288 size_t mi_good_size(size_t size);
    289 
    297 void mi_collect(bool force);
    298 
    303 void mi_stats_print(void* out);
    304 
    310 void mi_stats_print(mi_output_fun* out, void* arg);
    311 
    313 void mi_stats_reset(void);
    314 
    316 void mi_stats_merge(void);
    317 
    321 void mi_thread_init(void);
    322 
    327 void mi_thread_done(void);
    328 
    334 void mi_thread_stats_print_out(mi_output_fun* out, void* arg);
    335 
    342 typedef void (mi_deferred_free_fun)(bool force, unsigned long long heartbeat, void* arg);
    343 
    359 void mi_register_deferred_free(mi_deferred_free_fun* deferred_free, void* arg);
    360 
    366 typedef void (mi_output_fun)(const char* msg, void* arg);
    367 
    374 void mi_register_output(mi_output_fun* out, void* arg);
    375 
    381 typedef void (mi_error_fun)(int err, void* arg);
    382 
    398 void mi_register_error(mi_error_fun* errfun, void* arg);
    399 
    404 bool mi_is_in_heap_region(const void* p);
    405 
    406 
    419 int mi_reserve_huge_os_pages_interleave(size_t pages, size_t numa_nodes, size_t timeout_msecs);
    420 
    433 int mi_reserve_huge_os_pages_at(size_t pages, int numa_node, size_t timeout_msecs);
    434 
    435 
    440 bool mi_is_redirected();
    441 
    442 
    444 
    445 // ------------------------------------------------------
    446 // Aligned allocation
    447 // ------------------------------------------------------
    448 
    454 
    467 void* mi_malloc_aligned(size_t size, size_t alignment);
    468 void* mi_zalloc_aligned(size_t size, size_t alignment);
    469 void* mi_calloc_aligned(size_t count, size_t size, size_t alignment);
    470 void* mi_realloc_aligned(void* p, size_t newsize, size_t alignment);
    471 
    482 void* mi_malloc_aligned_at(size_t size, size_t alignment, size_t offset);
    483 void* mi_zalloc_aligned_at(size_t size, size_t alignment, size_t offset);
    484 void* mi_calloc_aligned_at(size_t count, size_t size, size_t alignment, size_t offset);
    485 void* mi_realloc_aligned_at(void* p, size_t newsize, size_t alignment, size_t offset);
    486 
    488 
    494 
    499 struct mi_heap_s;
    500 
    505 typedef struct mi_heap_s mi_heap_t;
    506 
    509 
    517 void mi_heap_delete(mi_heap_t* heap);
    518 
    526 void mi_heap_destroy(mi_heap_t* heap);
    527 
    532 
    536 
    543 
    545 void mi_heap_collect(mi_heap_t* heap, bool force);
    546 
    549 void* mi_heap_malloc(mi_heap_t* heap, size_t size);
    550 
    554 void* mi_heap_malloc_small(mi_heap_t* heap, size_t size);
    555 
    558 void* mi_heap_zalloc(mi_heap_t* heap, size_t size);
    559 
    562 void* mi_heap_calloc(mi_heap_t* heap, size_t count, size_t size);
    563 
    566 void* mi_heap_mallocn(mi_heap_t* heap, size_t count, size_t size);
    567 
    570 char* mi_heap_strdup(mi_heap_t* heap, const char* s);
    571 
    574 char* mi_heap_strndup(mi_heap_t* heap, const char* s, size_t n);
    575 
    578 char* mi_heap_realpath(mi_heap_t* heap, const char* fname, char* resolved_name);
    579 
    580 void* mi_heap_realloc(mi_heap_t* heap, void* p, size_t newsize);
    581 void* mi_heap_reallocn(mi_heap_t* heap, void* p, size_t count, size_t size);
    582 void* mi_heap_reallocf(mi_heap_t* heap, void* p, size_t newsize);
    583 
    584 void* mi_heap_malloc_aligned(mi_heap_t* heap, size_t size, size_t alignment);
    585 void* mi_heap_malloc_aligned_at(mi_heap_t* heap, size_t size, size_t alignment, size_t offset);
    586 void* mi_heap_zalloc_aligned(mi_heap_t* heap, size_t size, size_t alignment);
    587 void* mi_heap_zalloc_aligned_at(mi_heap_t* heap, size_t size, size_t alignment, size_t offset);
    588 void* mi_heap_calloc_aligned(mi_heap_t* heap, size_t count, size_t size, size_t alignment);
    589 void* mi_heap_calloc_aligned_at(mi_heap_t* heap, size_t count, size_t size, size_t alignment, size_t offset);
    590 void* mi_heap_realloc_aligned(mi_heap_t* heap, void* p, size_t newsize, size_t alignment);
    591 void* mi_heap_realloc_aligned_at(mi_heap_t* heap, void* p, size_t newsize, size_t alignment, size_t offset);
    592 
    594 
    595 
    604 
    605 void* mi_rezalloc(void* p, size_t newsize);
    606 void* mi_recalloc(void* p, size_t newcount, size_t size) ;
    607 
    608 void* mi_rezalloc_aligned(void* p, size_t newsize, size_t alignment);
    609 void* mi_rezalloc_aligned_at(void* p, size_t newsize, size_t alignment, size_t offset);
    610 void* mi_recalloc_aligned(void* p, size_t newcount, size_t size, size_t alignment);
    611 void* mi_recalloc_aligned_at(void* p, size_t newcount, size_t size, size_t alignment, size_t offset);
    612 
    613 void* mi_heap_rezalloc(mi_heap_t* heap, void* p, size_t newsize);
    614 void* mi_heap_recalloc(mi_heap_t* heap, void* p, size_t newcount, size_t size);
    615 
    616 void* mi_heap_rezalloc_aligned(mi_heap_t* heap, void* p, size_t newsize, size_t alignment);
    617 void* mi_heap_rezalloc_aligned_at(mi_heap_t* heap, void* p, size_t newsize, size_t alignment, size_t offset);
    618 void* mi_heap_recalloc_aligned(mi_heap_t* heap, void* p, size_t newcount, size_t size, size_t alignment);
    619 void* mi_heap_recalloc_aligned_at(mi_heap_t* heap, void* p, size_t newcount, size_t size, size_t alignment, size_t offset);
    620 
    622 
    628 
    640 #define mi_malloc_tp(tp) ((tp*)mi_malloc(sizeof(tp)))
    641 
    643 #define mi_zalloc_tp(tp) ((tp*)mi_zalloc(sizeof(tp)))
    644 
    646 #define mi_calloc_tp(tp,count) ((tp*)mi_calloc(count,sizeof(tp)))
    647 
    649 #define mi_mallocn_tp(tp,count) ((tp*)mi_mallocn(count,sizeof(tp)))
    650 
    652 #define mi_reallocn_tp(p,tp,count) ((tp*)mi_reallocn(p,count,sizeof(tp)))
    653 
    655 #define mi_heap_malloc_tp(hp,tp) ((tp*)mi_heap_malloc(hp,sizeof(tp)))
    656 
    658 #define mi_heap_zalloc_tp(hp,tp) ((tp*)mi_heap_zalloc(hp,sizeof(tp)))
    659 
    661 #define mi_heap_calloc_tp(hp,tp,count) ((tp*)mi_heap_calloc(hp,count,sizeof(tp)))
    662 
    664 #define mi_heap_mallocn_tp(hp,tp,count) ((tp*)mi_heap_mallocn(hp,count,sizeof(tp)))
    665 
    667 #define mi_heap_reallocn_tp(hp,p,tp,count) ((tp*)mi_heap_reallocn(p,count,sizeof(tp)))
    668 
    670 #define mi_heap_recalloc_tp(hp,p,tp,count) ((tp*)mi_heap_recalloc(p,count,sizeof(tp)))
    671 
    673 
    679 
    686 bool mi_heap_contains_block(mi_heap_t* heap, const void* p);
    687 
    696 bool mi_heap_check_owned(mi_heap_t* heap, const void* p);
    697 
    705 bool mi_check_owned(const void* p);
    706 
    709 typedef struct mi_heap_area_s {
    710  void* blocks;
    711  size_t reserved;
    712  size_t committed;
    713  size_t used;
    714  size_t block_size;
    716 
    724 typedef bool (mi_block_visit_fun)(const mi_heap_t* heap, const mi_heap_area_t* area, void* block, size_t block_size, void* arg);
    725 
    737 bool mi_heap_visit_blocks(const mi_heap_t* heap, bool visit_all_blocks, mi_block_visit_fun* visitor, void* arg);
    738 
    740 
    746 
    748 typedef enum mi_option_e {
    749  // stable options
    753  // the following options are experimental
    767 } mi_option_t;
    768 
    769 
    770 bool mi_option_enabled(mi_option_t option);
    771 void mi_option_enable(mi_option_t option, bool enable);
    772 void mi_option_enable_default(mi_option_t option, bool enable);
    773 
    774 long mi_option_get(mi_option_t option);
    775 void mi_option_set(mi_option_t option, long value);
    776 void mi_option_set_default(mi_option_t option, long value);
    777 
    778 
    780 
    787 
    788 void* mi_recalloc(void* p, size_t count, size_t size);
    789 size_t mi_malloc_size(const void* p);
    790 size_t mi_malloc_usable_size(const void *p);
    791 
    793 void mi_cfree(void* p);
    794 
    795 int mi_posix_memalign(void** p, size_t alignment, size_t size);
    796 int mi__posix_memalign(void** p, size_t alignment, size_t size);
    797 void* mi_memalign(size_t alignment, size_t size);
    798 void* mi_valloc(size_t size);
    799 
    800 void* mi_pvalloc(size_t size);
    801 void* mi_aligned_alloc(size_t alignment, size_t size);
    802 void* mi_reallocarray(void* p, size_t count, size_t size);
    803 
    804 void mi_free_size(void* p, size_t size);
    805 void mi_free_size_aligned(void* p, size_t size, size_t alignment);
    806 void mi_free_aligned(void* p, size_t alignment);
    807 
    809 
    822 
    824 void* mi_new(std::size_t n) noexcept(false);
    825 
    827 void* mi_new_n(size_t count, size_t size) noexcept(false);
    828 
    830 void* mi_new_aligned(std::size_t n, std::align_val_t alignment) noexcept(false);
    831 
    833 void* mi_new_nothrow(size_t n);
    834 
    836 void* mi_new_aligned_nothrow(size_t n, size_t alignment);
    837 
    839 void* mi_new_realloc(void* p, size_t newsize);
    840 
    842 void* mi_new_reallocn(void* p, size_t newcount, size_t size);
    843 
    851 template<class T> struct mi_stl_allocator { }
    852 
    854 
    void mi_option_enable_default(mi_option_t option, bool enable)
    +
    1 /* ----------------------------------------------------------------------------
    2 Copyright (c) 2018, Microsoft Research, Daan Leijen
    3 This is free software; you can redistribute it and/or modify it under the
    4 terms 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 
    83 
    87 
    91 void mi_free(void* p);
    92 
    97 void* mi_malloc(size_t size);
    98 
    103 void* mi_zalloc(size_t size);
    104 
    114 void* mi_calloc(size_t count, size_t size);
    115 
    128 void* mi_realloc(void* p, size_t newsize);
    129 
    140 void* mi_recalloc(void* p, size_t count, size_t size);
    141 
    155 void* mi_expand(void* p, size_t newsize);
    156 
    166 void* mi_mallocn(size_t count, size_t size);
    167 
    177 void* mi_reallocn(void* p, size_t count, size_t size);
    178 
    195 void* mi_reallocf(void* p, size_t newsize);
    196 
    197 
    206 char* mi_strdup(const char* s);
    207 
    217 char* mi_strndup(const char* s, size_t n);
    218 
    231 char* mi_realpath(const char* fname, char* resolved_name);
    232 
    234 
    235 // ------------------------------------------------------
    236 // Extended functionality
    237 // ------------------------------------------------------
    238 
    242 
    245 #define MI_SMALL_SIZE_MAX (128*sizeof(void*))
    246 
    254 void* mi_malloc_small(size_t size);
    255 
    263 void* mi_zalloc_small(size_t size);
    264 
    279 size_t mi_usable_size(void* p);
    280 
    290 size_t mi_good_size(size_t size);
    291 
    299 void mi_collect(bool force);
    300 
    305 void mi_stats_print(void* out);
    306 
    312 void mi_stats_print(mi_output_fun* out, void* arg);
    313 
    315 void mi_stats_reset(void);
    316 
    318 void mi_stats_merge(void);
    319 
    323 void mi_thread_init(void);
    324 
    329 void mi_thread_done(void);
    330 
    336 void mi_thread_stats_print_out(mi_output_fun* out, void* arg);
    337 
    344 typedef void (mi_deferred_free_fun)(bool force, unsigned long long heartbeat, void* arg);
    345 
    361 void mi_register_deferred_free(mi_deferred_free_fun* deferred_free, void* arg);
    362 
    368 typedef void (mi_output_fun)(const char* msg, void* arg);
    369 
    376 void mi_register_output(mi_output_fun* out, void* arg);
    377 
    383 typedef void (mi_error_fun)(int err, void* arg);
    384 
    400 void mi_register_error(mi_error_fun* errfun, void* arg);
    401 
    406 bool mi_is_in_heap_region(const void* p);
    407 
    408 
    421 int mi_reserve_huge_os_pages_interleave(size_t pages, size_t numa_nodes, size_t timeout_msecs);
    422 
    435 int mi_reserve_huge_os_pages_at(size_t pages, int numa_node, size_t timeout_msecs);
    436 
    437 
    442 bool mi_is_redirected();
    443 
    444 
    446 
    447 // ------------------------------------------------------
    448 // Aligned allocation
    449 // ------------------------------------------------------
    450 
    456 
    469 void* mi_malloc_aligned(size_t size, size_t alignment);
    470 void* mi_zalloc_aligned(size_t size, size_t alignment);
    471 void* mi_calloc_aligned(size_t count, size_t size, size_t alignment);
    472 void* mi_realloc_aligned(void* p, size_t newsize, size_t alignment);
    473 
    484 void* mi_malloc_aligned_at(size_t size, size_t alignment, size_t offset);
    485 void* mi_zalloc_aligned_at(size_t size, size_t alignment, size_t offset);
    486 void* mi_calloc_aligned_at(size_t count, size_t size, size_t alignment, size_t offset);
    487 void* mi_realloc_aligned_at(void* p, size_t newsize, size_t alignment, size_t offset);
    488 
    490 
    496 
    501 struct mi_heap_s;
    502 
    507 typedef struct mi_heap_s mi_heap_t;
    508 
    511 
    519 void mi_heap_delete(mi_heap_t* heap);
    520 
    528 void mi_heap_destroy(mi_heap_t* heap);
    529 
    534 
    538 
    545 
    547 void mi_heap_collect(mi_heap_t* heap, bool force);
    548 
    551 void* mi_heap_malloc(mi_heap_t* heap, size_t size);
    552 
    556 void* mi_heap_malloc_small(mi_heap_t* heap, size_t size);
    557 
    560 void* mi_heap_zalloc(mi_heap_t* heap, size_t size);
    561 
    564 void* mi_heap_calloc(mi_heap_t* heap, size_t count, size_t size);
    565 
    568 void* mi_heap_mallocn(mi_heap_t* heap, size_t count, size_t size);
    569 
    572 char* mi_heap_strdup(mi_heap_t* heap, const char* s);
    573 
    576 char* mi_heap_strndup(mi_heap_t* heap, const char* s, size_t n);
    577 
    580 char* mi_heap_realpath(mi_heap_t* heap, const char* fname, char* resolved_name);
    581 
    582 void* mi_heap_realloc(mi_heap_t* heap, void* p, size_t newsize);
    583 void* mi_heap_reallocn(mi_heap_t* heap, void* p, size_t count, size_t size);
    584 void* mi_heap_reallocf(mi_heap_t* heap, void* p, size_t newsize);
    585 
    586 void* mi_heap_malloc_aligned(mi_heap_t* heap, size_t size, size_t alignment);
    587 void* mi_heap_malloc_aligned_at(mi_heap_t* heap, size_t size, size_t alignment, size_t offset);
    588 void* mi_heap_zalloc_aligned(mi_heap_t* heap, size_t size, size_t alignment);
    589 void* mi_heap_zalloc_aligned_at(mi_heap_t* heap, size_t size, size_t alignment, size_t offset);
    590 void* mi_heap_calloc_aligned(mi_heap_t* heap, size_t count, size_t size, size_t alignment);
    591 void* mi_heap_calloc_aligned_at(mi_heap_t* heap, size_t count, size_t size, size_t alignment, size_t offset);
    592 void* mi_heap_realloc_aligned(mi_heap_t* heap, void* p, size_t newsize, size_t alignment);
    593 void* mi_heap_realloc_aligned_at(mi_heap_t* heap, void* p, size_t newsize, size_t alignment, size_t offset);
    594 
    596 
    597 
    606 
    607 void* mi_rezalloc(void* p, size_t newsize);
    608 void* mi_recalloc(void* p, size_t newcount, size_t size) ;
    609 
    610 void* mi_rezalloc_aligned(void* p, size_t newsize, size_t alignment);
    611 void* mi_rezalloc_aligned_at(void* p, size_t newsize, size_t alignment, size_t offset);
    612 void* mi_recalloc_aligned(void* p, size_t newcount, size_t size, size_t alignment);
    613 void* mi_recalloc_aligned_at(void* p, size_t newcount, size_t size, size_t alignment, size_t offset);
    614 
    615 void* mi_heap_rezalloc(mi_heap_t* heap, void* p, size_t newsize);
    616 void* mi_heap_recalloc(mi_heap_t* heap, void* p, size_t newcount, size_t size);
    617 
    618 void* mi_heap_rezalloc_aligned(mi_heap_t* heap, void* p, size_t newsize, size_t alignment);
    619 void* mi_heap_rezalloc_aligned_at(mi_heap_t* heap, void* p, size_t newsize, size_t alignment, size_t offset);
    620 void* mi_heap_recalloc_aligned(mi_heap_t* heap, void* p, size_t newcount, size_t size, size_t alignment);
    621 void* mi_heap_recalloc_aligned_at(mi_heap_t* heap, void* p, size_t newcount, size_t size, size_t alignment, size_t offset);
    622 
    624 
    633 
    645 #define mi_malloc_tp(tp) ((tp*)mi_malloc(sizeof(tp)))
    646 
    648 #define mi_zalloc_tp(tp) ((tp*)mi_zalloc(sizeof(tp)))
    649 
    651 #define mi_calloc_tp(tp,count) ((tp*)mi_calloc(count,sizeof(tp)))
    652 
    654 #define mi_mallocn_tp(tp,count) ((tp*)mi_mallocn(count,sizeof(tp)))
    655 
    657 #define mi_reallocn_tp(p,tp,count) ((tp*)mi_reallocn(p,count,sizeof(tp)))
    658 
    660 #define mi_heap_malloc_tp(hp,tp) ((tp*)mi_heap_malloc(hp,sizeof(tp)))
    661 
    663 #define mi_heap_zalloc_tp(hp,tp) ((tp*)mi_heap_zalloc(hp,sizeof(tp)))
    664 
    666 #define mi_heap_calloc_tp(hp,tp,count) ((tp*)mi_heap_calloc(hp,count,sizeof(tp)))
    667 
    669 #define mi_heap_mallocn_tp(hp,tp,count) ((tp*)mi_heap_mallocn(hp,count,sizeof(tp)))
    670 
    672 #define mi_heap_reallocn_tp(hp,p,tp,count) ((tp*)mi_heap_reallocn(p,count,sizeof(tp)))
    673 
    675 #define mi_heap_recalloc_tp(hp,p,tp,count) ((tp*)mi_heap_recalloc(p,count,sizeof(tp)))
    676 
    678 
    684 
    691 bool mi_heap_contains_block(mi_heap_t* heap, const void* p);
    692 
    701 bool mi_heap_check_owned(mi_heap_t* heap, const void* p);
    702 
    710 bool mi_check_owned(const void* p);
    711 
    714 typedef struct mi_heap_area_s {
    715  void* blocks;
    716  size_t reserved;
    717  size_t committed;
    718  size_t used;
    719  size_t block_size;
    721 
    729 typedef bool (mi_block_visit_fun)(const mi_heap_t* heap, const mi_heap_area_t* area, void* block, size_t block_size, void* arg);
    730 
    742 bool mi_heap_visit_blocks(const mi_heap_t* heap, bool visit_all_blocks, mi_block_visit_fun* visitor, void* arg);
    743 
    745 
    751 
    753 typedef enum mi_option_e {
    754  // stable options
    758  // the following options are experimental
    772 } mi_option_t;
    773 
    774 
    775 bool mi_option_enabled(mi_option_t option);
    776 void mi_option_enable(mi_option_t option, bool enable);
    777 void mi_option_enable_default(mi_option_t option, bool enable);
    778 
    779 long mi_option_get(mi_option_t option);
    780 void mi_option_set(mi_option_t option, long value);
    781 void mi_option_set_default(mi_option_t option, long value);
    782 
    783 
    785 
    792 
    793 void* mi_recalloc(void* p, size_t count, size_t size);
    794 size_t mi_malloc_size(const void* p);
    795 size_t mi_malloc_usable_size(const void *p);
    796 
    798 void mi_cfree(void* p);
    799 
    800 int mi_posix_memalign(void** p, size_t alignment, size_t size);
    801 int mi__posix_memalign(void** p, size_t alignment, size_t size);
    802 void* mi_memalign(size_t alignment, size_t size);
    803 void* mi_valloc(size_t size);
    804 
    805 void* mi_pvalloc(size_t size);
    806 void* mi_aligned_alloc(size_t alignment, size_t size);
    807 void* mi_reallocarray(void* p, size_t count, size_t size);
    808 
    809 void mi_free_size(void* p, size_t size);
    810 void mi_free_size_aligned(void* p, size_t size, size_t alignment);
    811 void mi_free_aligned(void* p, size_t alignment);
    812 
    814 
    827 
    829 void* mi_new(std::size_t n) noexcept(false);
    830 
    832 void* mi_new_n(size_t count, size_t size) noexcept(false);
    833 
    835 void* mi_new_aligned(std::size_t n, std::align_val_t alignment) noexcept(false);
    836 
    838 void* mi_new_nothrow(size_t n);
    839 
    841 void* mi_new_aligned_nothrow(size_t n, size_t alignment);
    842 
    844 void* mi_new_realloc(void* p, size_t newsize);
    845 
    847 void* mi_new_reallocn(void* p, size_t newcount, size_t size);
    848 
    856 template<class T> struct mi_stl_allocator { }
    857 
    859 
    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.
    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_reallocn(void *p, size_t count, size_t size)
    Re-allocate memory to count elements of size bytes.
    @@ -118,17 +118,17 @@ $(document).ready(function(){initNavTree('mimalloc-doc_8h_source.html','');});
    void mi_stats_merge(void)
    Merge thread local statistics with the main statistics and reset.
    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...
    void mi_option_set_default(mi_option_t option, long value)
    -
    void() mi_error_fun(int err, void *arg)
    Type of error callback functions.
    Definition: mimalloc-doc.h:381
    +
    void() mi_error_fun(int err, void *arg)
    Type of error callback functions.
    Definition: mimalloc-doc.h:383
    void * mi_rezalloc(void *p, size_t newsize)
    -
    Eagerly commit segments (4MiB) (enabled by default).
    Definition: mimalloc-doc.h:754
    +
    Eagerly commit segments (4MiB) (enabled by default).
    Definition: mimalloc-doc.h:759
    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)
    -
    Eagerly commit large (256MiB) memory regions (enabled by default, except on Windows)
    Definition: mimalloc-doc.h:755
    +
    Eagerly commit large (256MiB) memory regions (enabled by default, except on Windows)
    Definition: mimalloc-doc.h:760
    void mi_cfree(void *p)
    Just as free but also checks if the pointer p belongs to our heap.
    void * mi_recalloc_aligned(void *p, size_t newcount, size_t size, size_t alignment)
    -
    Definition: mimalloc-doc.h:766
    +
    Definition: mimalloc-doc.h:771
    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:710
    +
    void * blocks
    start of the area containing heap blocks
    Definition: mimalloc-doc.h:715
    void * mi_realloc_aligned(void *p, size_t newsize, size_t alignment)
    int mi__posix_memalign(void **p, size_t alignment, size_t size)
    void mi_free(void *p)
    Free previously allocated memory.
    @@ -144,37 +144,37 @@ $(document).ready(function(){initNavTree('mimalloc-doc_8h_source.html','');});
    void * mi_heap_rezalloc_aligned_at(mi_heap_t *heap, void *p, size_t newsize, size_t alignment, size_t offset)
    void * mi_zalloc(size_t size)
    Allocate zero-initialized size bytes.
    void * mi_heap_rezalloc(mi_heap_t *heap, void *p, size_t newsize)
    -
    The number of segments per thread to keep cached.
    Definition: mimalloc-doc.h:758
    +
    The number of segments per thread to keep cached.
    Definition: mimalloc-doc.h:763
    void * mi_heap_calloc(mi_heap_t *heap, size_t count, size_t size)
    Allocate count zero-initialized elements in a specific heap.
    void * mi_heap_calloc_aligned(mi_heap_t *heap, size_t count, size_t size, size_t alignment)
    bool mi_is_redirected()
    Is the C runtime malloc API redirected?
    -
    size_t block_size
    size in bytes of one block
    Definition: mimalloc-doc.h:714
    +
    size_t block_size
    size in bytes of one block
    Definition: mimalloc-doc.h:719
    void * mi_reallocarray(void *p, size_t count, size_t size)
    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...
    -
    void() mi_deferred_free_fun(bool force, unsigned long long heartbeat, void *arg)
    Type of deferred free functions.
    Definition: mimalloc-doc.h:342
    +
    void() mi_deferred_free_fun(bool force, unsigned long long heartbeat, void *arg)
    Type of deferred free functions.
    Definition: mimalloc-doc.h:344
    bool mi_is_in_heap_region(const void *p)
    Is a pointer part of our heap?
    void mi_option_enable(mi_option_t option, bool enable)
    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_realloc(void *p, size_t newsize)
    Re-allocate memory to newsize bytes.
    -
    The number of huge OS pages (1GiB in size) to reserve at the start of the program.
    Definition: mimalloc-doc.h:757
    +
    The number of huge OS pages (1GiB in size) to reserve at the start of the program.
    Definition: mimalloc-doc.h:762
    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)
    void * mi_rezalloc_aligned_at(void *p, size_t newsize, size_t alignment, size_t offset)
    -
    Reset page memory after mi_option_reset_delay milliseconds when it becomes free.
    Definition: mimalloc-doc.h:759
    +
    Reset page memory after mi_option_reset_delay milliseconds when it becomes free.
    Definition: mimalloc-doc.h:764
    void mi_thread_done(void)
    Uninitialize mimalloc on a thread.
    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.
    -
    Pretend there are at most N NUMA nodes.
    Definition: mimalloc-doc.h:762
    +
    Pretend there are at most N NUMA nodes.
    Definition: mimalloc-doc.h:767
    void * mi_malloc(size_t size)
    Allocate size bytes.
    bool mi_option_enabled(mi_option_t option)
    void mi_register_error(mi_error_fun *errfun, void *arg)
    Register an error callback function.
    -
    Experimental.
    Definition: mimalloc-doc.h:763
    +
    Experimental.
    Definition: mimalloc-doc.h:768
    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:724
    +
    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:729
    void * mi_heap_recalloc(mi_heap_t *heap, void *p, size_t newcount, size_t size)
    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:751
    -
    Experimental.
    Definition: mimalloc-doc.h:760
    +
    Print error messages to stderr.
    Definition: mimalloc-doc.h:756
    +
    Experimental.
    Definition: mimalloc-doc.h:765
    void * mi_heap_rezalloc_aligned(mi_heap_t *heap, void *p, size_t newsize, size_t alignment)
    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_memalign(size_t alignment, size_t size)
    @@ -182,11 +182,11 @@ $(document).ready(function(){initNavTree('mimalloc-doc_8h_source.html','');});
    bool mi_heap_contains_block(mi_heap_t *heap, const void *p)
    Does a heap contain a pointer to a previously allocated block?
    void mi_heap_collect(mi_heap_t *heap, bool force)
    Release outstanding resources in a specific heap.
    void * mi_heap_recalloc_aligned_at(mi_heap_t *heap, void *p, size_t newcount, size_t size, size_t alignment, size_t offset)
    -
    Print verbose messages to stderr.
    Definition: mimalloc-doc.h:752
    +
    Print verbose messages to stderr.
    Definition: mimalloc-doc.h:757
    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.
    -
    OS tag to assign to mimalloc'd memory.
    Definition: mimalloc-doc.h:765
    +
    OS tag to assign to mimalloc'd memory.
    Definition: mimalloc-doc.h:770
    mi_heap_t * mi_heap_get_default()
    Get the default heap that is used for mi_malloc() et al.
    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 ...
    void * mi_aligned_alloc(size_t alignment, size_t size)
    @@ -194,30 +194,30 @@ $(document).ready(function(){initNavTree('mimalloc-doc_8h_source.html','');});
    void mi_thread_init(void)
    Initialize mimalloc on a thread.
    size_t mi_good_size(size_t size)
    Return the used allocation size.
    void mi_stats_print(void *out)
    Print the main statistics.
    -
    Experimental.
    Definition: mimalloc-doc.h:764
    +
    Experimental.
    Definition: mimalloc-doc.h:769
    void * mi_heap_recalloc_aligned(mi_heap_t *heap, void *p, size_t newcount, size_t size, size_t alignment)
    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:709
    +
    An area of heap space contains blocks of a single size.
    Definition: mimalloc-doc.h:714
    void mi_thread_stats_print_out(mi_output_fun *out, void *arg)
    Print out heap statistics for this thread.
    -
    Print statistics to stderr when the program is done.
    Definition: mimalloc-doc.h:750
    +
    Print statistics to stderr when the program is done.
    Definition: mimalloc-doc.h:755
    void * mi_zalloc_aligned(size_t size, size_t alignment)
    -
    size_t reserved
    bytes reserved for this area
    Definition: mimalloc-doc.h:711
    -
    struct mi_heap_s mi_heap_t
    Type of first-class heaps.
    Definition: mimalloc-doc.h:505
    -
    size_t used
    bytes in use by allocated blocks
    Definition: mimalloc-doc.h:713
    +
    size_t reserved
    bytes reserved for this area
    Definition: mimalloc-doc.h:716
    +
    struct mi_heap_s mi_heap_t
    Type of first-class heaps.
    Definition: mimalloc-doc.h:507
    +
    size_t used
    bytes in use by allocated blocks
    Definition: mimalloc-doc.h:718
    void mi_register_deferred_free(mi_deferred_free_fun *deferred_free, void *arg)
    Register a deferred free function.
    void mi_free_size(void *p, size_t size)
    void mi_collect(bool force)
    Eagerly free memory.
    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_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 (2MiB in size) if possible.
    Definition: mimalloc-doc.h:756
    +
    Use large OS pages (2MiB in size) if possible.
    Definition: mimalloc-doc.h:761
    void * mi_heap_reallocn(mi_heap_t *heap, void *p, size_t count, size_t size)
    void mi_register_output(mi_output_fun *out, void *arg)
    Register an output function.
    -
    std::allocator implementation for mimalloc for use in STL containers.
    Definition: mimalloc-doc.h:851
    +
    std::allocator implementation for mimalloc for use in STL containers.
    Definition: mimalloc-doc.h:856
    void * mi_heap_malloc_small(mi_heap_t *heap, size_t size)
    Allocate a small object in a specific heap.
    void * mi_heap_realloc(mi_heap_t *heap, void *p, size_t newsize)
    size_t mi_malloc_usable_size(const void *p)
    -
    void() mi_output_fun(const char *msg, void *arg)
    Type of output functions.
    Definition: mimalloc-doc.h:366
    +
    void() mi_output_fun(const char *msg, void *arg)
    Type of output functions.
    Definition: mimalloc-doc.h:368
    char * mi_strdup(const char *s)
    Allocate and duplicate a string.
    void * mi_heap_realloc_aligned_at(mi_heap_t *heap, void *p, size_t newsize, size_t alignment, size_t offset)
    void * mi_reallocf(void *p, size_t newsize)
    Re-allocate memory to newsize bytes,.
    @@ -230,11 +230,11 @@ $(document).ready(function(){initNavTree('mimalloc-doc_8h_source.html','');});
    mi_heap_t * mi_heap_get_backing()
    Get the backing heap.
    void mi_free_aligned(void *p, size_t alignment)
    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...
    -
    Delay in milli-seconds before resetting a page (100ms by default)
    Definition: mimalloc-doc.h:761
    +
    Delay in milli-seconds before resetting a page (100ms by default)
    Definition: mimalloc-doc.h:766
    mi_heap_t * mi_heap_new()
    Create a new heap that can be used for allocation.
    void * mi_heap_malloc(mi_heap_t *heap, size_t size)
    Allocate in a specific heap.
    -
    size_t committed
    current committed bytes of this area
    Definition: mimalloc-doc.h:712
    -
    mi_option_t
    Runtime options.
    Definition: mimalloc-doc.h:748
    +
    size_t committed
    current committed bytes of this area
    Definition: mimalloc-doc.h:717
    +
    mi_option_t
    Runtime options.
    Definition: mimalloc-doc.h:753
    bool mi_heap_check_owned(mi_heap_t *heap, const void *p)
    Check safely if any pointer is part of a heap.
    mi_heap_t * mi_heap_set_default(mi_heap_t *heap)
    Set the default heap to use for mi_malloc() et al.
    diff --git a/docs/mimalloc-logo.svg b/docs/mimalloc-logo.svg index 7b6231bd..672c7e41 100644 --- a/docs/mimalloc-logo.svg +++ b/docs/mimalloc-logo.svg @@ -36,15 +36,15 @@ inkscape:pageopacity="0.0" inkscape:pageshadow="2" inkscape:zoom="23.706667" - inkscape:cx="34.419045" + inkscape:cx="24.864771" inkscape:cy="35.79485" inkscape:document-units="mm" inkscape:current-layer="layer1" showgrid="false" inkscape:window-width="3840" - inkscape:window-height="2160" - inkscape:window-x="0" - inkscape:window-y="0" + inkscape:window-height="2050" + inkscape:window-x="-12" + inkscape:window-y="-12" inkscape:window-maximized="1" inkscape:snap-object-midpoints="false" inkscape:snap-bbox="false" @@ -126,17 +126,15 @@ style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:2.28797817px;font-family:RoutedGothicEx;-inkscape-font-specification:'RoutedGothicEx, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;writing-mode:lr-tb;text-anchor:start;stroke-width:0.28599727" id="path6525" /> - m + id="text848"> + + diff --git a/docs/modules.html b/docs/modules.html index 91bf17e8..9858d6ad 100644 --- a/docs/modules.html +++ b/docs/modules.html @@ -37,7 +37,7 @@ Logo
    mi-malloc -  1.4 +  1.6
    diff --git a/docs/overrides.html b/docs/overrides.html index 3b5d9bd3..2a6c51e9 100644 --- a/docs/overrides.html +++ b/docs/overrides.html @@ -37,7 +37,7 @@ Logo
    mi-malloc -  1.4 +  1.6
    @@ -116,12 +116,13 @@ $(document).ready(function(){initNavTree('overrides.html','');});
  • 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).

    +

    (Note: macOS support for dynamic overriding is recent, please report any issues.)

    Windows

    -

    Overriding on Windows is robust but requires that you link your program explicitly with the mimalloc DLL and use the C-runtime library as a DLL (using the /MD or /MDd switch). Moreover, you need to ensure the mimalloc-redirect.dll (or mimalloc-redirect32.dll) is available in the same folder as the main mimalloc-override.dll at runtime (as it is a dependency). The redirection DLL ensures that all calls to the C runtime malloc API get redirected to mimalloc (in mimalloc-override.dll).

    -

    To ensure the mimalloc DLL is loaded at run-time 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). See the mimalloc-override-test project for an example on how to use this. For best performance on Windows with C++, it is highly recommended to also override the new/delete operations (by including mimalloc-new-delete.h a single(!) source file in your project).

    +

    Overriding on Windows is robust and has the particular advantage to be able to redirect all malloc/free calls that go through the (dynamic) C runtime allocator, including those from other DLL's or libraries.

    +

    The overriding on Windows requires that you link your program explicitly with the mimalloc DLL and use the C-runtime library as a DLL (using the /MD or /MDd switch). Also, the mimalloc-redirect.dll (or mimalloc-redirect32.dll) must be available in the same folder as the main mimalloc-override.dll at runtime (as it is a dependency). The redirection DLL ensures that all calls to the C runtime malloc API get redirected to mimalloc (in mimalloc-override.dll).

    +

    To ensure the mimalloc DLL is loaded at run-time 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). See the mimalloc-override-test project for an example on how to use this. For best performance on Windows with C++, it is also recommended to also override the new/delete operations (by including mimalloc-new-delete.h a single(!) source file in your project).

    The environment variable MIMALLOC_DISABLE_REDIRECT=1 can be used to disable dynamic overriding at run-time. Use MIMALLOC_VERBOSE=1 to check if mimalloc was successfully redirected.

    -

    (Note: in principle, it is possible to patch existing executables that are linked with the dynamic C runtime (ucrtbase.dll) by just putting the mimalloc-override.dll into the import table (and putting mimalloc-redirect.dll in the same folder) Such patching can be done for example with CFF Explorer).

    +

    (Note: in principle, it is possible to even patch existing executables without any recompilation if they are linked with the dynamic C runtime (ucrtbase.dll) – just put the mimalloc-override.dll into the import table (and put mimalloc-redirect.dll in the same folder) Such patching can be done for example with CFF Explorer).

    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/pages.html b/docs/pages.html index ad5549bf..8fcd6f08 100644 --- a/docs/pages.html +++ b/docs/pages.html @@ -37,7 +37,7 @@ Logo
    mi-malloc -  1.4 +  1.6
    diff --git a/docs/using.html b/docs/using.html index c5dc12e7..047e35ec 100644 --- a/docs/using.html +++ b/docs/using.html @@ -37,7 +37,7 @@ Logo
    mi-malloc -  1.4 +  1.6