Files
cppdraft_translate/cppdraft/c/malloc.md
2025-10-25 03:02:53 +03:00

3.3 KiB
Raw Blame History

[c.malloc]

20 Memory management library [mem]

20.2 Memory [memory]

20.2.12 C library memory allocation [c.malloc]

1

#

[Note 1:

The header declares the functions described in this subclause.

— end note]

🔗

void* aligned_alloc(size_t alignment, size_t size); void* calloc(size_t nmemb, size_t size); void* malloc(size_t size);

2

#

Effects: These functions have the semantics specified in the C standard library.

3

#

Remarks: These functions do not attempt to allocate storage by calling ::operator new() ([new.delete]).

4

#

These functions implicitly create objects ([intro.object]) in the returned region of storage and return a pointer to a suitable created object.

In the case of calloc, the objects are created before the storage is zeroed.

🔗

void* realloc(void* ptr, size_t size);

5

#

Preconditions: free(ptr) has well-defined behavior.

6

#

Effects: If ptr is not null and size is zero, the behavior is erroneous and the effects are implementation-defined.

Otherwise, this function has the semantics specified in the C standard library.

7

#

Remarks: This function does not attempt to allocate storage by calling ::operator new() ([new.delete]).

When a non-null pointer is returned, this function implicitly creates objects ([intro.object]) in the returned region of storage and returns a pointer to a suitable created object.

The objects are created before the storage is copied.

🔗

void free(void* ptr);

8

#

Effects: This function has the semantics specified in the C standard library.

9

#

Remarks: This function does not attempt to deallocate storage by calling::operator delete().

See also: ISO/IEC 9899:2024, 7.22.3