1
1
/* ----------------------------------------------------------------------------
2
- Copyright (c) 2018-2022 , Microsoft Research, Daan Leijen
2
+ Copyright (c) 2018-2023 , Microsoft Research, Daan Leijen
3
3
This is free software; you can redistribute it and/or modify it under the
4
4
terms of the MIT license. A copy of the license can be found in the file
5
5
"LICENSE" at the root of this distribution.
@@ -8,7 +8,7 @@ terms of the MIT license. A copy of the license can be found in the file
8
8
#ifndef MIMALLOC_H
9
9
#define MIMALLOC_H
10
10
11
- #define MI_MALLOC_VERSION 209 // major + 2 digits minor
11
+ #define MI_MALLOC_VERSION 212 // major + 2 digits minor
12
12
13
13
// ------------------------------------------------------
14
14
// Compiler specific attributes
@@ -284,7 +284,7 @@ mi_decl_export int mi_reserve_huge_os_pages_at_ex(size_t pages, int numa_node,
284
284
mi_decl_export int mi_reserve_os_memory_ex (size_t size, bool commit, bool allow_large, bool exclusive, mi_arena_id_t * arena_id) mi_attr_noexcept;
285
285
mi_decl_export bool mi_manage_os_memory_ex (void * start, size_t size, bool is_committed, bool is_large, bool is_zero, int numa_node, bool exclusive, mi_arena_id_t * arena_id) mi_attr_noexcept;
286
286
287
- #if MI_MALLOC_VERSION >= 200
287
+ #if MI_MALLOC_VERSION >= 182
288
288
// Create a heap that only allocates in the specified arena
289
289
mi_decl_nodiscard mi_decl_export mi_heap_t * mi_heap_new_in_arena (mi_arena_id_t arena_id);
290
290
#endif
@@ -318,35 +318,40 @@ mi_decl_export int mi_reserve_huge_os_pages(size_t pages, double max_secs, size
318
318
319
319
typedef enum mi_option_e {
320
320
// stable options
321
- mi_option_show_errors,
322
- mi_option_show_stats,
323
- mi_option_verbose,
324
- // some of the following options are experimental
325
- // (deprecated options are kept for binary backward compatibility with v1.x versions)
326
- mi_option_eager_commit,
327
- mi_option_deprecated_eager_region_commit,
328
- mi_option_deprecated_reset_decommits,
329
- mi_option_large_os_pages, // use large (2MiB) OS pages, implies eager commit
330
- mi_option_reserve_huge_os_pages, // reserve N huge OS pages (1GiB) at startup
321
+ mi_option_show_errors, // print error messages
322
+ mi_option_show_stats, // print statistics on termination
323
+ mi_option_verbose, // print verbose messages
324
+ // the following options are experimental (see src/options.h)
325
+ mi_option_eager_commit, // eager commit segments? (after `eager_commit_delay` segments) (=1)
326
+ mi_option_arena_eager_commit, // eager commit arenas? Use 2 to enable just on overcommit systems (=2)
327
+ mi_option_purge_decommits, // should a memory purge decommit (or only reset) (=1)
328
+ mi_option_allow_large_os_pages, // allow large (2MiB) OS pages, implies eager commit
329
+ mi_option_reserve_huge_os_pages, // reserve N huge OS pages (1GiB/page) at startup
331
330
mi_option_reserve_huge_os_pages_at, // reserve huge OS pages at a specific NUMA node
332
- mi_option_reserve_os_memory, // reserve specified amount of OS memory at startup
331
+ mi_option_reserve_os_memory, // reserve specified amount of OS memory in an arena at startup
333
332
mi_option_deprecated_segment_cache,
334
- mi_option_page_reset,
335
- mi_option_abandoned_page_decommit,
336
- mi_option_deprecated_segment_reset,
337
- mi_option_eager_commit_delay,
338
- mi_option_decommit_delay,
339
- mi_option_use_numa_nodes, // 0 = use available numa nodes, otherwise use at most N nodes.
340
- mi_option_limit_os_alloc, // 1 = do not use OS memory for allocation (but only reserved arenas)
341
- mi_option_os_tag,
342
- mi_option_max_errors,
343
- mi_option_max_warnings,
344
- mi_option_max_segment_reclaim,
345
- mi_option_allow_decommit,
346
- mi_option_segment_decommit_delay,
347
- mi_option_decommit_extend_delay,
348
- mi_option_destroy_on_exit,
349
- _mi_option_last
333
+ mi_option_deprecated_page_reset,
334
+ mi_option_abandoned_page_purge, // immediately purge delayed purges on thread termination
335
+ mi_option_deprecated_segment_reset,
336
+ mi_option_eager_commit_delay,
337
+ mi_option_purge_delay, // memory purging is delayed by N milli seconds; use 0 for immediate purging or -1 for no purging at all.
338
+ mi_option_use_numa_nodes, // 0 = use all available numa nodes, otherwise use at most N nodes.
339
+ mi_option_limit_os_alloc, // 1 = do not use OS memory for allocation (but only programmatically reserved arenas)
340
+ mi_option_os_tag, // tag used for OS logging (macOS only for now)
341
+ mi_option_max_errors, // issue at most N error messages
342
+ mi_option_max_warnings, // issue at most N warning messages
343
+ mi_option_max_segment_reclaim,
344
+ mi_option_destroy_on_exit, // if set, release all memory on exit; sometimes used for dynamic unloading but can be unsafe.
345
+ mi_option_arena_reserve, // initial memory size in KiB for arena reservation (1GiB on 64-bit)
346
+ mi_option_arena_purge_mult,
347
+ mi_option_purge_extend_delay,
348
+ _mi_option_last,
349
+ // legacy option names
350
+ mi_option_large_os_pages = mi_option_allow_large_os_pages,
351
+ mi_option_eager_region_commit = mi_option_arena_eager_commit,
352
+ mi_option_reset_decommits = mi_option_purge_decommits,
353
+ mi_option_reset_delay = mi_option_purge_delay,
354
+ mi_option_abandoned_page_reset = mi_option_abandoned_page_purge
350
355
} mi_option_t ;
351
356
352
357
@@ -356,8 +361,9 @@ mi_decl_export void mi_option_disable(mi_option_t option);
356
361
mi_decl_export void mi_option_set_enabled (mi_option_t option, bool enable);
357
362
mi_decl_export void mi_option_set_enabled_default (mi_option_t option, bool enable);
358
363
359
- mi_decl_nodiscard mi_decl_export long mi_option_get (mi_option_t option);
360
- mi_decl_nodiscard mi_decl_export long mi_option_get_clamp (mi_option_t option, long min, long max);
364
+ mi_decl_nodiscard mi_decl_export long mi_option_get (mi_option_t option);
365
+ mi_decl_nodiscard mi_decl_export long mi_option_get_clamp (mi_option_t option, long min, long max);
366
+ mi_decl_nodiscard mi_decl_export size_t mi_option_get_size (mi_option_t option);
361
367
mi_decl_export void mi_option_set (mi_option_t option, long value);
362
368
mi_decl_export void mi_option_set_default (mi_option_t option, long value);
363
369
@@ -477,11 +483,13 @@ template<class T1,class T2> bool operator==(const mi_stl_allocator<T1>& , const
477
483
template <class T1 ,class T2 > bool operator !=(const mi_stl_allocator<T1>& , const mi_stl_allocator<T2>& ) mi_attr_noexcept { return false ; }
478
484
479
485
480
- #if (__cplusplus >= 201103L) || (_MSC_VER > 1900) // C++11
486
+ #if (__cplusplus >= 201103L) || (_MSC_VER >= 1900) // C++11
487
+ #define MI_HAS_HEAP_STL_ALLOCATOR 1
488
+
481
489
#include < memory> // std::shared_ptr
482
490
483
491
// Common base class for STL allocators in a specific heap
484
- template <class T , bool destroy > struct _mi_heap_stl_allocator_common : public _mi_stl_allocator_common <T> {
492
+ template <class T , bool _mi_destroy > struct _mi_heap_stl_allocator_common : public _mi_stl_allocator_common <T> {
485
493
using typename _mi_stl_allocator_common<T>::size_type;
486
494
using typename _mi_stl_allocator_common<T>::value_type;
487
495
using typename _mi_stl_allocator_common<T>::pointer;
@@ -500,18 +508,18 @@ template<class T, bool destroy> struct _mi_heap_stl_allocator_common : public _m
500
508
#endif
501
509
502
510
void collect (bool force) { mi_heap_collect (this ->heap .get (), force); }
503
- template <class U > bool is_equal (const _mi_heap_stl_allocator_common<U, destroy >& x) const { return (this ->heap == x.heap ); }
511
+ template <class U > bool is_equal (const _mi_heap_stl_allocator_common<U, _mi_destroy >& x) const { return (this ->heap == x.heap ); }
504
512
505
513
protected:
506
514
std::shared_ptr<mi_heap_t > heap;
507
515
template <class U , bool D> friend struct _mi_heap_stl_allocator_common ;
508
516
509
517
_mi_heap_stl_allocator_common () {
510
518
mi_heap_t * hp = mi_heap_new ();
511
- this ->heap .reset (hp, (destroy ? &heap_destroy : &heap_delete)); /* calls heap_delete/destroy when the refcount drops to zero */
519
+ this ->heap .reset (hp, (_mi_destroy ? &heap_destroy : &heap_delete)); /* calls heap_delete/destroy when the refcount drops to zero */
512
520
}
513
521
_mi_heap_stl_allocator_common (const _mi_heap_stl_allocator_common& x) mi_attr_noexcept : heap(x.heap) { }
514
- template <class U > _mi_heap_stl_allocator_common (const _mi_heap_stl_allocator_common<U, destroy >& x) mi_attr_noexcept : heap(x.heap) { }
522
+ template <class U > _mi_heap_stl_allocator_common (const _mi_heap_stl_allocator_common<U, _mi_destroy >& x) mi_attr_noexcept : heap(x.heap) { }
515
523
516
524
private:
517
525
static void heap_delete (mi_heap_t * hp) { if (hp != NULL ) { mi_heap_delete (hp); } }
0 commit comments