mi-malloc  1.0
Heap Allocation

First-class heaps that can be destroyed in one go. More...

Typedefs

typedef struct mi_heap_s mi_heap_t
 Type of first-class heaps. More...
 

Functions

mi_heap_tmi_heap_new ()
 Create a new heap that can be used for allocation. More...
 
void mi_heap_delete (mi_heap_t *heap)
 Delete a previously allocated heap. More...
 
void mi_heap_destroy (mi_heap_t *heap)
 Destroy a heap, freeing all its still allocated blocks. More...
 
mi_heap_tmi_heap_set_default (mi_heap_t *heap)
 Set the default heap to use for mi_malloc() et al. More...
 
mi_heap_tmi_heap_get_default ()
 Get the default heap that is used for mi_malloc() et al. More...
 
mi_heap_tmi_heap_get_backing ()
 Get the backing heap. More...
 
void mi_heap_collect (mi_heap_t *heap, bool force)
 Release outstanding resources in a specific heap. More...
 
void * mi_heap_malloc (mi_heap_t *heap, size_t size)
 Allocate in a specific heap. More...
 
void * mi_heap_malloc_small (mi_heap_t *heap, size_t size)
 Allocate a small object in a specific heap. More...
 
void * mi_heap_zalloc (mi_heap_t *heap, size_t size)
 Allocate zero-initialized in a specific heap. More...
 
void * mi_heap_calloc (mi_heap_t *heap, size_t count, size_t size)
 Allocate count zero-initialized elements in a specific heap. More...
 
void * mi_heap_mallocn (mi_heap_t *heap, size_t count, size_t size)
 Allocate count elements in a specific heap. More...
 
char * mi_heap_strdup (mi_heap_t *heap, const char *s)
 Duplicate a string in a specific heap. More...
 
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. More...
 
char * mi_heap_realpath (mi_heap_t *heap, const char *fname, char *resolved_name)
 Resolve a file path name using a specific heap to allocate the result. More...
 
void * mi_heap_realloc (mi_heap_t *heap, void *p, size_t newsize)
 
void * mi_heap_reallocn (mi_heap_t *heap, void *p, size_t count, size_t size)
 
void * mi_heap_reallocf (mi_heap_t *heap, void *p, size_t newsize)
 
void * mi_heap_malloc_aligned (mi_heap_t *heap, size_t size, size_t alignment)
 
void * mi_heap_malloc_aligned_at (mi_heap_t *heap, size_t size, size_t alignment, size_t offset)
 
void * mi_heap_zalloc_aligned (mi_heap_t *heap, size_t size, size_t alignment)
 
void * mi_heap_zalloc_aligned_at (mi_heap_t *heap, size_t size, size_t alignment, size_t offset)
 
void * mi_heap_calloc_aligned (mi_heap_t *heap, size_t count, size_t size, size_t alignment)
 
void * mi_heap_calloc_aligned_at (mi_heap_t *heap, size_t count, size_t size, size_t alignment, size_t offset)
 
void * mi_heap_realloc_aligned (mi_heap_t *heap, void *p, size_t newsize, size_t alignment)
 
void * mi_heap_realloc_aligned_at (mi_heap_t *heap, void *p, size_t newsize, size_t alignment, size_t offset)
 

Detailed Description

First-class heaps that can be destroyed in one go.

Typedef Documentation

◆ mi_heap_t

typedef struct mi_heap_s mi_heap_t

Type of first-class heaps.

A heap can only be used for (re)allocation in the thread that created this heap! Any allocated blocks can be freed by any other thread though.

Function Documentation

◆ mi_heap_calloc()

void* mi_heap_calloc ( mi_heap_t heap,
size_t  count,
size_t  size 
)

Allocate count zero-initialized elements in a specific heap.

See also
mi_calloc()

◆ mi_heap_calloc_aligned()

void* mi_heap_calloc_aligned ( mi_heap_t heap,
size_t  count,
size_t  size,
size_t  alignment 
)

◆ mi_heap_calloc_aligned_at()

void* mi_heap_calloc_aligned_at ( mi_heap_t heap,
size_t  count,
size_t  size,
size_t  alignment,
size_t  offset 
)

◆ mi_heap_collect()

void mi_heap_collect ( mi_heap_t heap,
bool  force 
)

Release outstanding resources in a specific heap.

◆ mi_heap_delete()

void mi_heap_delete ( mi_heap_t heap)

Delete a previously allocated heap.

This will release resources and migrate any still allocated blocks in this heap (efficienty) to the default heap.

If heap is the default heap, the default heap is set to the backing heap.

◆ mi_heap_destroy()

void mi_heap_destroy ( mi_heap_t heap)

Destroy a heap, freeing all its still allocated blocks.

Use with care as this will free all blocks still allocated in the heap. However, this can be a very efficient way to free all heap memory in one go.

If heap is the default heap, the default heap is set to the backing heap.

◆ mi_heap_get_backing()

mi_heap_t* mi_heap_get_backing ( )

Get the backing heap.

The backing heap is the initial default heap for a thread and always available for allocations. It cannot be destroyed or deleted except by exiting the thread.

◆ mi_heap_get_default()

mi_heap_t* mi_heap_get_default ( )

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

Returns
The current default heap.

◆ mi_heap_malloc()

void* mi_heap_malloc ( mi_heap_t heap,
size_t  size 
)

Allocate in a specific heap.

See also
mi_malloc()

◆ mi_heap_malloc_aligned()

void* mi_heap_malloc_aligned ( mi_heap_t heap,
size_t  size,
size_t  alignment 
)

◆ mi_heap_malloc_aligned_at()

void* mi_heap_malloc_aligned_at ( mi_heap_t heap,
size_t  size,
size_t  alignment,
size_t  offset 
)

◆ mi_heap_malloc_small()

void* mi_heap_malloc_small ( mi_heap_t heap,
size_t  size 
)

Allocate a small object in a specific heap.

size must be smaller or equal to MI_SMALL_SIZE_MAX().

See also
mi_malloc()

◆ mi_heap_mallocn()

void* mi_heap_mallocn ( mi_heap_t heap,
size_t  count,
size_t  size 
)

Allocate count elements in a specific heap.

See also
mi_mallocn()

◆ mi_heap_new()

mi_heap_t* mi_heap_new ( )

Create a new heap that can be used for allocation.

◆ mi_heap_realloc()

void* mi_heap_realloc ( mi_heap_t heap,
void *  p,
size_t  newsize 
)

◆ mi_heap_realloc_aligned()

void* mi_heap_realloc_aligned ( mi_heap_t heap,
void *  p,
size_t  newsize,
size_t  alignment 
)

◆ mi_heap_realloc_aligned_at()

void* mi_heap_realloc_aligned_at ( mi_heap_t heap,
void *  p,
size_t  newsize,
size_t  alignment,
size_t  offset 
)

◆ mi_heap_reallocf()

void* mi_heap_reallocf ( mi_heap_t heap,
void *  p,
size_t  newsize 
)

◆ mi_heap_reallocn()

void* mi_heap_reallocn ( mi_heap_t heap,
void *  p,
size_t  count,
size_t  size 
)

◆ mi_heap_realpath()

char* mi_heap_realpath ( mi_heap_t heap,
const char *  fname,
char *  resolved_name 
)

Resolve a file path name using a specific heap to allocate the result.

See also
mi_realpath()

◆ mi_heap_set_default()

mi_heap_t* mi_heap_set_default ( mi_heap_t heap)

Set the default heap to use for mi_malloc() et al.

Parameters
heapThe new default heap.
Returns
The previous default heap.

◆ mi_heap_strdup()

char* mi_heap_strdup ( mi_heap_t heap,
const char *  s 
)

Duplicate a string in a specific heap.

See also
mi_strdup()

◆ mi_heap_strndup()

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.

See also
mi_strndup()

◆ mi_heap_zalloc()

void* mi_heap_zalloc ( mi_heap_t heap,
size_t  size 
)

Allocate zero-initialized in a specific heap.

See also
mi_zalloc()

◆ mi_heap_zalloc_aligned()

void* mi_heap_zalloc_aligned ( mi_heap_t heap,
size_t  size,
size_t  alignment 
)

◆ mi_heap_zalloc_aligned_at()

void* mi_heap_zalloc_aligned_at ( mi_heap_t heap,
size_t  size,
size_t  alignment,
size_t  offset 
)