Memory management

suggest change

The standard library declares its dynamic-memory functions in <stdlib.h>:

Check allocation results before dereferencing them. Guard multiplication used to calculate an allocation size against SIZE_MAX overflow, or use calloc, which must detect overflow in count * size.

aligned_alloc requires a valid alignment supported by the implementation. C11 as originally published required size to be an integral multiple of alignment; a later defect correction removed that restriction, but rounding up remains useful when targeting older implementations. Storage returned by aligned_alloc can be released with free.

alloca is not part of ISO C. It allocates implementation-defined stack storage that is released only when the calling function returns, cannot report failure portably, and can exhaust limited stack space. Prefer standard allocation functions or an automatic array with a known, bounded size.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents