mi-malloc 3.6/2.5/1.15
Loading...
Searching...
No Matches
Thread-local heaps

v3: Thread local heaps. More...

Typedefs

typedef struct mi_theap_s mi_theap_t
 Type of thread-local heaps.

Functions

mi_theap_t * mi_heap_theap (mi_heap_t *heap)
 Return the thread-local theap for the given heap.
void mi_theap_collect (mi_theap_t *theap, bool force)
 Release outstanding resources in a specific theap.
void mi_theap_delete (mi_theap_t *theap)
 experimental: Abandon a theap's pages and delete the theap, preserving its heap and live blocks.
void mi_theap_quiescent_abandon (mi_theap_t *theap)
 experimental: Abandon all pages, preserving the theap and live blocks for reuse.
mi_theap_t * mi_theap_set_default (mi_theap_t *theap)
 Set the default thread-local theap to use in the current thread for mi_malloc() et al.
mi_theap_t * mi_theap_get_default ()
 Get the default theap that is used for mi_malloc() et al.
void * mi_theap_malloc (mi_theap_t *theap, size_t size)
 Allocate in a specific theap.
void * mi_theap_malloc_small (mi_theap_t *theap, size_t size)
 Allocate a small object in a specific theap.
void * mi_theap_wmalloc_small (mi_theap_t *theap, size_t wsize)
 As mi_wmalloc_small(), using a non-NULL theap belonging to the calling thread.
void * mi_theap_wzalloc_small (mi_theap_t *theap, size_t wsize)
 As mi_wzalloc_small(), using a non-NULL theap belonging to the calling thread.
void * mi_theap_zalloc (mi_theap_t *theap, size_t size)
 Allocate zero-initialized in a specific heap.
void * mi_theap_zalloc_small (mi_theap_t *theap, size_t size)
 Allocate a small object in a specific theap.
void * mi_theap_calloc (mi_theap_t *theap, size_t count, size_t size)
void * mi_theap_malloc_aligned (mi_theap_t *theap, size_t size, size_t alignment)
void * mi_theap_realloc (mi_theap_t *theap, void *p, size_t newsize)
void * mi_theap_zalloc_aligned (mi_theap_t *theap, size_t size, size_t alignment)
 As mi_zalloc_aligned(), using a theap belonging to the calling thread.
void * mi_theap_rezalloc (mi_theap_t *theap, void *p, size_t newsize)
 As mi_rezalloc(), using a theap belonging to the calling thread.
void * mi_theap_realloc_aligned (mi_theap_t *theap, void *p, size_t newsize, size_t alignment)
 As mi_realloc_aligned(), using a theap belonging to the calling thread.
void * mi_theap_rezalloc_aligned (mi_theap_t *theap, void *p, size_t newsize, size_t alignment)
 As mi_rezalloc_aligned(), using a theap belonging to the calling thread.
void mi_theap_guarded_set_sample_rate (mi_theap_t *theap, size_t sample_rate, size_t seed)
 experimental: Set guarded-allocation sampling for a theap belonging to the calling thread.
void mi_theap_guarded_set_size_bound (mi_theap_t *theap, size_t min, size_t max)
 experimental: Set inclusive size bounds in bytes for guarded allocations in this theap.
bool mi_theap_visit_blocks (const mi_theap_t *theap, bool visit_blocks, mi_block_visit_fun *visitor, void *arg)

Detailed Description

v3: Thread local heaps.

The use of thread-local heaps is discouraged and only recommended for special cases like runtime systems that keep their own thread-local state. The "theaps" are thread-local heaps that v3 uses internally to implement efficient first-class heaps.

v1,v2: the mi_heap_t heaps in v1/v2 are exactly these mi_theap_t theaps in v3.

Typedef Documentation

◆ mi_theap_t

typedef struct mi_theap_s mi_theap_t

Type of thread-local heaps.

Function Documentation

◆ mi_heap_theap()

mi_theap_t * mi_heap_theap ( mi_heap_t * heap)

Return the thread-local theap for the given heap.

Parameters
heapThe owning heap.
Returns
The theap that serves thread-local allocations for the given Heaps. This can be used by runtime systems to request the thread-local theap once and then use it in its allocation functions (like mi_theap_malloc() or mi_theap_malloc_small() ) to avoid re-looking up the theap at each allocation call.

This is never NULL: if the theap could not be created, or if the current thread has already terminated (after mi_thread_done()), a special empty theap is returned instead. Allocation through such an empty theap returns NULL

◆ mi_theap_calloc()

void * mi_theap_calloc ( mi_theap_t * theap,
size_t count,
size_t size )

◆ mi_theap_collect()

void mi_theap_collect ( mi_theap_t * theap,
bool force )

Release outstanding resources in a specific theap.

◆ mi_theap_delete()

void mi_theap_delete ( mi_theap_t * theap)

experimental: Abandon a theap's pages and delete the theap, preserving its heap and live blocks.

Only the owning thread may call this function.

◆ mi_theap_get_default()

mi_theap_t * mi_theap_get_default ( )

Get the default theap that is used for mi_malloc() et al.

for the current thread.

Returns
The current default theap.

◆ mi_theap_guarded_set_sample_rate()

void mi_theap_guarded_set_sample_rate ( mi_theap_t * theap,
size_t sample_rate,
size_t seed )

experimental: Set guarded-allocation sampling for a theap belonging to the calling thread.

sample_rate is measured in bytes: 0 disables sampling, 1 guards every eligible allocation. seed is a reproducible sampling seed, or 0 for a random seed. Requires MI_GUARDED.

◆ mi_theap_guarded_set_size_bound()

void mi_theap_guarded_set_size_bound ( mi_theap_t * theap,
size_t min,
size_t max )

experimental: Set inclusive size bounds in bytes for guarded allocations in this theap.

Only the owning thread may call this function. Requires MI_GUARDED.

◆ mi_theap_malloc()

void * mi_theap_malloc ( mi_theap_t * theap,
size_t size )

Allocate in a specific theap.

See also
mi_malloc()

◆ mi_theap_malloc_aligned()

void * mi_theap_malloc_aligned ( mi_theap_t * theap,
size_t size,
size_t alignment )

◆ mi_theap_malloc_small()

void * mi_theap_malloc_small ( mi_theap_t * theap,
size_t size )

Allocate a small object in a specific theap.

size must be smaller or equal to MI_SMALL_SIZE_MAX().

See also
mi_malloc_small()

◆ mi_theap_quiescent_abandon()

void mi_theap_quiescent_abandon ( mi_theap_t * theap)

experimental: Abandon all pages, preserving the theap and live blocks for reuse.

The owner must be the calling thread or quiescent outside mimalloc. Heap and theap deletion must not run concurrently.

◆ mi_theap_realloc()

void * mi_theap_realloc ( mi_theap_t * theap,
void * p,
size_t newsize )

◆ mi_theap_realloc_aligned()

void * mi_theap_realloc_aligned ( mi_theap_t * theap,
void * p,
size_t newsize,
size_t alignment )

As mi_realloc_aligned(), using a theap belonging to the calling thread.

◆ mi_theap_rezalloc()

void * mi_theap_rezalloc ( mi_theap_t * theap,
void * p,
size_t newsize )

As mi_rezalloc(), using a theap belonging to the calling thread.

p must be NULL or originate from a zero-initialized allocation.

◆ mi_theap_rezalloc_aligned()

void * mi_theap_rezalloc_aligned ( mi_theap_t * theap,
void * p,
size_t newsize,
size_t alignment )

As mi_rezalloc_aligned(), using a theap belonging to the calling thread.

p must be NULL or originate from a zero-initialized allocation.

◆ mi_theap_set_default()

mi_theap_t * mi_theap_set_default ( mi_theap_t * theap)

Set the default thread-local theap to use in the current thread for mi_malloc() et al.

Parameters
theapThe new default theap.
Returns
The previous default theap. By default it will point to the theap belonging to the main heap (mi_heap_main()).

◆ mi_theap_visit_blocks()

bool mi_theap_visit_blocks ( const mi_theap_t * theap,
bool visit_blocks,
mi_block_visit_fun * visitor,
void * arg )
Deprecated
Visit areas and optionally allocated blocks in a thread-local heap. Prevent concurrent mutation during the visit; prefer mi_heap_visit_blocks().
Returns
true if the visit completed.

◆ mi_theap_wmalloc_small()

void * mi_theap_wmalloc_small ( mi_theap_t * theap,
size_t wsize )

As mi_wmalloc_small(), using a non-NULL theap belonging to the calling thread.

wsize must not exceed MI_SMALL_WSIZE_MAX.

◆ mi_theap_wzalloc_small()

void * mi_theap_wzalloc_small ( mi_theap_t * theap,
size_t wsize )

As mi_wzalloc_small(), using a non-NULL theap belonging to the calling thread.

wsize must not exceed MI_SMALL_WSIZE_MAX.

◆ mi_theap_zalloc()

void * mi_theap_zalloc ( mi_theap_t * theap,
size_t size )

Allocate zero-initialized in a specific heap.

See also
mi_zalloc()

◆ mi_theap_zalloc_aligned()

void * mi_theap_zalloc_aligned ( mi_theap_t * theap,
size_t size,
size_t alignment )

As mi_zalloc_aligned(), using a theap belonging to the calling thread.

◆ mi_theap_zalloc_small()

void * mi_theap_zalloc_small ( mi_theap_t * theap,
size_t size )

Allocate a small object in a specific theap.

size must be smaller or equal to MI_SMALL_SIZE_MAX().

See also
mi_zalloc_small()