Reference

free_sized(3)

C23 sized deallocation functions

Part of free_aligned_sized(3).

NAME

free_sized, free_aligned_sized – C23 sized deallocation functions

SYNOPSIS

Standard C Library (libc, -lc)

#include <stdlib.h>

void

free_sized(void *ptr, size_t size);

void

free_aligned_sized(void *ptr, size_t alignment, size_t size);

DESCRIPTION

The free_sized() function deallocates the memory referenced by ptr that was previously allocated by malloc(3), realloc(3), or calloc(3). The size argument shall equal the size passed to the allocation function. The result of an aligned_alloc(3) may not be passed to free_sized().

The free_aligned_sized() function deallocates memory referenced by ptr that was previously allocated by aligned_alloc(3). The alignment and size arguments shall equal the values supplied to the allocation function. The result of an malloc(3), calloc(3), or realloc(3) may not be passed to free_aligned_sized().

If ptr is neither a null pointer nor a pointer returned by the allocation functions described above for the corresponding deallocation function, the behaviour is undefined, and so is supplying a size or alignment that does not match the original allocation.

IMPLEMENTATION NOTES

The C standard permits an implementation to ignore the size and alignment hints. The current implementation forwards to free(3) without validating these arguments, so behaviour remains correct for well-formed use.

These functions will be wired to the system allocator's sized deallocation, once supported, as with the rest of the memory allocation API, so that size and alignment hints are used for performance and security benefits. That behaviour conforms to the practice recommended for each function in the C standard.

SEE ALSO

aligned_alloc(3), calloc(3), free(3), jemalloc(3), malloc(3), realloc(3)

STANDARDS

The free_sized() and free_aligned_sized() functions conform to ISO/IEC 9899:2024 (“ISO C23”).

AUTHOR

Faraz Vahedi ⟨[email protected]⟩