20 General utilities library [utilities]

20.7 Memory [memory]

20.7.13 C library [c.malloc]

Table [tab:util.hdr.cstdlib] describes the header <cstdlib>.

Table 45 — Header <cstdlib> synopsis
TypeName(s)
Functions: calloc malloc
free realloc

The contents are the same as the Standard C library header <stdlib.h>, with the following changes:

The functions calloc(), malloc(), and realloc() do not attempt to allocate storage by calling ::operator new() ([support.dynamic]).

The function free() does not attempt to deallocate storage by calling ::operator delete().

See also: ISO C Clause 7.11.2.

Storage allocated directly with malloc(), calloc(), or realloc() is implicitly declared reachable (see [basic.stc.dynamic.safety]) on allocation, ceases to be declared reachable on deallocation, and need not cease to be declared reachable as the result of an undeclare_reachable() call. [ Note: This allows existing C libraries to remain unaffected by restrictions on pointers that are not safely derived, at the expense of providing far fewer garbage collection and leak detection options for malloc()-allocated objects. It also allows malloc() to be implemented with a separate allocation arena, bypassing the normal declare_reachable() implementation. The above functions should never intentionally be used as a replacement for declare_reachable(), and newly written code is strongly encouraged to treat memory allocated with these functions as though it were allocated with operator new.  — end note ]

Table [tab:util.hdr.cstring] describes the header <cstring>.

Table 46 — Header <cstring> synopsis
TypeName(s)
Macro: NULL
Type: size_t
Functions: memchr memcmp
memcpy memmove memset

The contents are the same as the Standard C library header <string.h>, with the change to memchr() specified in [c.strings].

See also: ISO C Clause 7.11.2.