mi-malloc 3.7/2.5/1.15
Loading...
Searching...
No Matches
Small allocations

Allocation and freeing of small objects (of at most MI_SMALL_SIZE_MAX bytes). More...

Macros

#define MI_SMALL_WSIZE_MAX
 Maximum number of machine words allowed for mi_wmalloc_small().
#define MI_SMALL_SIZE_MAX
 Maximum size in bytes allowed for small allocations in mi_malloc_small, mi_zalloc_small, mi_heap_malloc_small, mi_heap_zalloc_small, mi_theap_malloc_small, and mi_theap_zalloc_small (128*sizeof(size_t), or 1 KiB on 64-bit systems).

Functions

void * mi_malloc_small (size_t size)
 Allocate a small object.
void * mi_wmalloc_small (size_t wsize)
 v3: Allocate a small object with its size expressed in machine words.
void * mi_wzalloc_small (size_t wsize)
 v3: As mi_wmalloc_small(), but zero-initialize the allocation.
size_t mi_wsize_from_size (size_t size)
 v3: Convert a byte size to a number of sizeof(size_t) words, rounding up.
void * mi_zalloc_small (size_t size)
 Allocate a zero initialized small object.
void mi_free_small (void *p)
 v3: Can be used to free an object that was allocated with mi_malloc_small() or any allocation with a size < MI_SMALL_SIZE_MAX()
void mi_free_small_nonnull (void *p)
 v3: Can be used to free an object that was allocated with mi_malloc_small() or any allocation with a size < MI_SMALL_SIZE_MAX()
void mi_free_small_local (void *p)
 v3: As mi_free_small(), but the block's page must be owned by the calling thread.
void mi_free_small_local_nonnull (void *p)
 As mi_free_small_local(), but p must not be NULL.

Detailed Description

Allocation and freeing of small objects (of at most MI_SMALL_SIZE_MAX bytes).

These are meant for runtime systems that know the size is small, and do not check the size – use with care!

Macro Definition Documentation

◆ MI_SMALL_SIZE_MAX

#define MI_SMALL_SIZE_MAX

Maximum size in bytes allowed for small allocations in mi_malloc_small, mi_zalloc_small, mi_heap_malloc_small, mi_heap_zalloc_small, mi_theap_malloc_small, and mi_theap_zalloc_small (128*sizeof(size_t), or 1 KiB on 64-bit systems).

◆ MI_SMALL_WSIZE_MAX

#define MI_SMALL_WSIZE_MAX

Maximum number of machine words allowed for mi_wmalloc_small().

A machine word is sizeof(size_t) bytes.

Function Documentation

◆ mi_free_small()

void mi_free_small ( void * p)

v3: Can be used to free an object that was allocated with mi_malloc_small() or any allocation with a size < MI_SMALL_SIZE_MAX()

Parameters
pPointer that was returned from mi_malloc_small et al. (or NULL )

This function is meant for use in run-time systems for best performance and does not check if the pointer was indeed allocated as a small object – use with care!

See also
mi_free_small_nonnull()
mi_malloc_small()
mi_zalloc_small()
mi_heap_malloc_small()
mi_heap_zalloc_small()
mi_theap_malloc_small()
mi_theap_zalloc_small()

◆ mi_free_small_local()

void mi_free_small_local ( void * p)

v3: As mi_free_small(), but the block's page must be owned by the calling thread.

p may be NULL. The caller must guarantee both the small size and page ownership.

◆ mi_free_small_local_nonnull()

void mi_free_small_local_nonnull ( void * p)

As mi_free_small_local(), but p must not be NULL.

◆ mi_free_small_nonnull()

void mi_free_small_nonnull ( void * p)

v3: Can be used to free an object that was allocated with mi_malloc_small() or any allocation with a size < MI_SMALL_SIZE_MAX()

Parameters
pPointer that was returned from mi_malloc_small et al. Cannot be NULL !

This function is meant for use in run-time systems for best performance and does not check if the pointer was indeed allocated as a small object or not NULL – use with care!

See also
mi_free_small()
mi_malloc_small()
mi_zalloc_small()
mi_heap_malloc_small()
mi_heap_zalloc_small()
mi_theap_malloc_small()
mi_theap_zalloc_small()

◆ mi_malloc_small()

void * mi_malloc_small ( size_t size)

Allocate a small object.

Parameters
sizeThe size in bytes, can be at most MI_SMALL_SIZE_MAX.
Returns
a pointer to newly allocated memory of at least size bytes, or NULL if out of memory. This function is meant for use in run-time systems for best performance and does not check if size was indeed small – use with care!

◆ mi_wmalloc_small()

void * mi_wmalloc_small ( size_t wsize)

v3: Allocate a small object with its size expressed in machine words.

Parameters
wsizeThe number of words, at most MI_SMALL_WSIZE_MAX. Each word is sizeof(size_t) bytes, not necessarily the size of a pointer.
Returns
A pointer to newly allocated memory of at least wsize times sizeof(size_t) bytes, or NULL if out of memory. Like mi_malloc_small(), this function is intended for runtime systems and does not check the size bound in release builds. The caller must ensure that wsize is small enough. Free the result with mi_free() or mi_free_small().
See also
mi_malloc_small(), mi_malloc_csize()

◆ mi_wsize_from_size()

size_t mi_wsize_from_size ( size_t size)

v3: Convert a byte size to a number of sizeof(size_t) words, rounding up.

size must not exceed SIZE_MAX - (sizeof(size_t) - 1) to avoid overflow.

◆ mi_wzalloc_small()

void * mi_wzalloc_small ( size_t wsize)

v3: As mi_wmalloc_small(), but zero-initialize the allocation.

wsize must not exceed MI_SMALL_WSIZE_MAX.

◆ mi_zalloc_small()

void * mi_zalloc_small ( size_t size)

Allocate a zero initialized small object.

Parameters
sizeThe size in bytes, can be at most MI_SMALL_SIZE_MAX.
Returns
a pointer to newly allocated zero-initialized memory of at least size bytes, or NULL if out of memory. This function is meant for use in run-time systems for best performance and does not check if size was indeed small – use with care!