@@ -8,7 +8,7 @@ terms of the MIT license. A copy of the license can be found in the file
88#ifndef MIMALLOC_H
99#define MIMALLOC_H
1010
11- #define MI_MALLOC_VERSION 217 // major + 2 digits minor
11+ #define MI_MALLOC_VERSION 188 // major + 2 digits minor
1212
1313// ------------------------------------------------------
1414// Compiler specific attributes
@@ -97,7 +97,6 @@ terms of the MIT license. A copy of the license can be found in the file
9797
9898#include < stddef.h> // size_t
9999#include < stdbool.h> // bool
100- #include < stdint.h> // INTPTR_MAX
101100
102101#ifdef __cplusplus
103102extern " C" {
@@ -149,6 +148,7 @@ typedef void (mi_cdecl mi_error_fun)(int err, void* arg);
149148mi_decl_export void mi_register_error (mi_error_fun* fun, void * arg);
150149
151150mi_decl_export void mi_collect (bool force) mi_attr_noexcept;
151+ mi_decl_export void mi_collect_reduce (size_t target_thread_owned) mi_attr_noexcept;
152152mi_decl_export int mi_version (void ) mi_attr_noexcept;
153153mi_decl_export void mi_stats_reset (void ) mi_attr_noexcept;
154154mi_decl_export void mi_stats_merge (void ) mi_attr_noexcept;
@@ -259,11 +259,12 @@ typedef struct mi_heap_area_s {
259259 size_t used; // number of allocated blocks
260260 size_t block_size; // size in bytes of each block
261261 size_t full_block_size; // size in bytes of a full block including padding and metadata.
262+ int heap_tag; // heap tag associated with this area
262263} mi_heap_area_t ;
263264
264265typedef bool (mi_cdecl mi_block_visit_fun)(const mi_heap_t * heap, const mi_heap_area_t * area, void * block, size_t block_size, void * arg);
265266
266- mi_decl_export bool mi_heap_visit_blocks (const mi_heap_t * heap, bool visit_all_blocks , mi_block_visit_fun* visitor, void * arg);
267+ mi_decl_export bool mi_heap_visit_blocks (const mi_heap_t * heap, bool visit_blocks , mi_block_visit_fun* visitor, void * arg);
267268
268269// Experimental
269270mi_decl_nodiscard mi_decl_export bool mi_is_in_heap_region (const void * p) mi_attr_noexcept;
@@ -289,8 +290,31 @@ mi_decl_export bool mi_manage_os_memory_ex(void* start, size_t size, bool is_co
289290mi_decl_nodiscard mi_decl_export mi_heap_t * mi_heap_new_in_arena (mi_arena_id_t arena_id);
290291#endif
291292
293+
294+ // Experimental: allow sub-processes whose memory segments stay separated (and no reclamation between them)
295+ // Used for example for separate interpreter's in one process.
296+ typedef void * mi_subproc_id_t ;
297+ mi_decl_export mi_subproc_id_t mi_subproc_main (void );
298+ mi_decl_export mi_subproc_id_t mi_subproc_new (void );
299+ mi_decl_export void mi_subproc_delete (mi_subproc_id_t subproc);
300+ mi_decl_export void mi_subproc_add_current_thread (mi_subproc_id_t subproc); // this should be called right after a thread is created (and no allocation has taken place yet)
301+
302+ // Experimental: visit abandoned heap areas (from threads that have been terminated)
303+ mi_decl_export bool mi_abandoned_visit_blocks (mi_subproc_id_t subproc_id, int heap_tag, bool visit_blocks, mi_block_visit_fun* visitor, void * arg);
304+
305+ // Experimental: create a new heap with a specified heap tag. Set `allow_destroy` to false to allow the thread
306+ // to reclaim abandoned memory (with a compatible heap_tag and arena_id) but in that case `mi_heap_destroy` will
307+ // fall back to `mi_heap_delete`.
308+ mi_decl_nodiscard mi_decl_export mi_heap_t * mi_heap_new_ex (int heap_tag, bool allow_destroy, mi_arena_id_t arena_id);
309+
292310// deprecated
293- mi_decl_export int mi_reserve_huge_os_pages (size_t pages, double max_secs, size_t * pages_reserved) mi_attr_noexcept;
311+ mi_decl_export int mi_reserve_huge_os_pages (size_t pages, double max_secs, size_t * pages_reserved) mi_attr_noexcept;
312+
313+ // Experimental: objects followed by a guard page.
314+ // A sample rate of 0 disables guarded objects, while 1 uses a guard page for every object.
315+ // A seed of 0 uses a random start point. Only objects within the size bound are eligable for guard pages.
316+ mi_decl_export void mi_heap_guarded_set_sample_rate (mi_heap_t * heap, size_t sample_rate, size_t seed);
317+ mi_decl_export void mi_heap_guarded_set_size_bound (mi_heap_t * heap, size_t min, size_t max);
294318
295319
296320// ------------------------------------------------------
@@ -332,7 +356,7 @@ typedef enum mi_option_e {
332356 mi_option_deprecated_segment_cache,
333357 mi_option_deprecated_page_reset,
334358 mi_option_abandoned_page_purge, // immediately purge delayed purges on thread termination
335- mi_option_deprecated_segment_reset,
359+ mi_option_deprecated_segment_reset,
336360 mi_option_eager_commit_delay, // the first N segments per thread are not eagerly committed (but per page in the segment on demand)
337361 mi_option_purge_delay, // memory purging is delayed by N milli seconds; use 0 for immediate purging or -1 for no purging at all. (=10)
338362 mi_option_use_numa_nodes, // 0 = use all available numa nodes, otherwise use at most N nodes.
@@ -348,6 +372,13 @@ typedef enum mi_option_e {
348372 mi_option_abandoned_reclaim_on_free, // allow to reclaim an abandoned segment on a free (=1)
349373 mi_option_disallow_arena_alloc, // 1 = do not use arena's for allocation (except if using specific arena id's)
350374 mi_option_retry_on_oom, // retry on out-of-memory for N milli seconds (=400), set to 0 to disable retries. (only on windows)
375+ mi_option_visit_abandoned, // allow visiting heap blocks from abandoned threads (=0)
376+ mi_option_guarded_min, // only used when building with MI_GUARDED: minimal rounded object size for guarded objects (=0)
377+ mi_option_guarded_max, // only used when building with MI_GUARDED: maximal rounded object size for guarded objects (=0)
378+ mi_option_guarded_precise, // disregard minimal alignment requirement to always place guarded blocks exactly in front of a guard page (=0)
379+ mi_option_guarded_sample_rate, // 1 out of N allocations in the min/max range will be guarded (=1000)
380+ mi_option_guarded_sample_seed, // can be set to allow for a (more) deterministic re-execution when a guard page is triggered (=0)
381+ mi_option_target_segments_per_thread, // experimental (=0)
351382 _mi_option_last,
352383 // legacy option names
353384 mi_option_large_os_pages = mi_option_allow_large_os_pages,
0 commit comments