mi-malloc 3.7/2.5/1.15
Loading...
Searching...
No Matches
Allocation with Usable Sizes

v3: Allocate or free memory while reporting the usable size in bytes. More...

Functions

void * mi_umalloc (size_t size, size_t *pusable_size)
 Allocate size bytes and report the usable size through pusable_size.
void * mi_uzalloc (size_t size, size_t *pusable_size)
 Allocate size zero-initialized bytes and report the usable size through pusable_size.
void * mi_ucalloc (size_t count, size_t size, size_t *pusable_size)
 Allocate count zero-initialized elements of size bytes and report the usable size.
void * mi_urealloc (void *p, size_t newsize, size_t *pusable_size_pre, size_t *pusable_size_post)
 Reallocate p to newsize bytes and report the old and new usable sizes.
void mi_ufree (void *p, size_t *pusable_size)
 Free p and report its usable size, or 0 if p is NULL.
void * mi_umalloc_aligned (size_t size, size_t alignment, size_t *pusable_size)
 As mi_malloc_aligned(), additionally reporting the usable size on success.
void * mi_uzalloc_aligned (size_t size, size_t alignment, size_t *pusable_size)
 As mi_zalloc_aligned(), additionally reporting the usable size on success.
void * mi_urealloc_aligned (void *p, size_t newsize, size_t alignment, size_t *pusable_size_pre, size_t *pusable_size_post)
 As mi_realloc_aligned(), additionally reporting the old and new usable sizes (as mi_urealloc()).
void * mi_umalloc_small (size_t size, size_t *pusable_size)
 As mi_malloc_small(), additionally reporting the usable size on success.
void * mi_uzalloc_small (size_t size, size_t *pusable_size)
 As mi_zalloc_small(), additionally reporting the usable size on success.

Detailed Description

v3: Allocate or free memory while reporting the usable size in bytes.

The reported size always equals mi_usable_size() of the returned (or freed) pointer, and can be used as the writable capacity. Size output pointers may be NULL. Allocation size outputs are only valid on success; they need not be cleared on failure.

Function Documentation

◆ mi_ucalloc()

void * mi_ucalloc ( size_t count,
size_t size,
size_t * pusable_size )

Allocate count zero-initialized elements of size bytes and report the usable size.

Returns
The allocation, or NULL on failure or multiplication overflow.
See also
mi_calloc()

◆ mi_ufree()

void mi_ufree ( void * p,
size_t * pusable_size )

Free p and report its usable size, or 0 if p is NULL.

See also
mi_free()

◆ mi_umalloc()

void * mi_umalloc ( size_t size,
size_t * pusable_size )

Allocate size bytes and report the usable size through pusable_size.

Returns
The allocation, or NULL on failure.
See also
mi_malloc()

◆ mi_umalloc_aligned()

void * mi_umalloc_aligned ( size_t size,
size_t alignment,
size_t * pusable_size )

As mi_malloc_aligned(), additionally reporting the usable size on success.

◆ mi_umalloc_small()

void * mi_umalloc_small ( size_t size,
size_t * pusable_size )

As mi_malloc_small(), additionally reporting the usable size on success.

size must not exceed MI_SMALL_SIZE_MAX.

◆ mi_urealloc()

void * mi_urealloc ( void * p,
size_t newsize,
size_t * pusable_size_pre,
size_t * pusable_size_post )

Reallocate p to newsize bytes and report the old and new usable sizes.

pusable_size_pre is 0 for NULL input; pusable_size_post is valid on success.

Returns
The reallocated block, or NULL on failure without freeing p.
See also
mi_realloc()

◆ mi_urealloc_aligned()

void * mi_urealloc_aligned ( void * p,
size_t newsize,
size_t alignment,
size_t * pusable_size_pre,
size_t * pusable_size_post )

As mi_realloc_aligned(), additionally reporting the old and new usable sizes (as mi_urealloc()).

◆ mi_uzalloc()

void * mi_uzalloc ( size_t size,
size_t * pusable_size )

Allocate size zero-initialized bytes and report the usable size through pusable_size.

Returns
The allocation, or NULL on failure.
See also
mi_zalloc()

◆ mi_uzalloc_aligned()

void * mi_uzalloc_aligned ( size_t size,
size_t alignment,
size_t * pusable_size )

As mi_zalloc_aligned(), additionally reporting the usable size on success.

◆ mi_uzalloc_small()

void * mi_uzalloc_small ( size_t size,
size_t * pusable_size )

As mi_zalloc_small(), additionally reporting the usable size on success.

size must not exceed MI_SMALL_SIZE_MAX.