MALLOC(3POSIX)
π MALLOC(3POSIX) β the POSIX Programmer's Manual, bestie edition π
okay so this is MALLOC(3POSIX), from the POSIX Programmer's Manual, and we're about to make memory allocation make sense, fr fr. no cap, you're gonna get it. π«Ά
πΈ PROLOG πΈ
This manual page is part of the POSIX Programmer's Manual. Heads up though: the Linux implementation of this interface may differ (so go peek at the corresponding Linux manual page for the details on Linux behavior), or the interface might not even be implemented on Linux at all. π
β¨ NAME β¨
malloc β a memory allocator
π SYNOPSIS π
#include <stdlib.h>
void *malloc(size_t size);
π DESCRIPTION π
The functionality described on this reference page is aligned with the ISO C standard. And listen β any conflict between the requirements described here and the ISO C standard is unintentional. This volume of POSIX.1β2017 defers to the ISO C standard. it's giving "the C standard is the main character here". π
The malloc() function shall allocate unused space for an object whose size in bytes is specified by size and whose value is unspecified.
The order and contiguity of storage allocated by successive calls to malloc() is unspecified. π« The pointer returned, if the allocation succeeds, shall be suitably aligned so that it may be assigned to a pointer to any type of object and then used to access such an object in the space allocated (until the space is explicitly freed or reallocated). Every single such allocation shall yield a pointer to an object that's disjoint from any other object. The pointer returned points to the start (lowest byte address) of the allocated space. If the space cannot be allocated, a null pointer shall be returned. And if the size of the space requested is 0, the behavior is implementation-defined: either a null pointer shall be returned, or the behavior shall be as if the size were some non-zero value β except that the behavior is undefined if the returned pointer is used to access an object. π¨ so like, do not touch that pointer, periodt.
π₯ RETURN VALUE π₯
Upon successful completion with size not equal to 0, malloc() shall return a pointer to the allocated space. If size is 0, either:
- A null pointer shall be returned and
errnomay be set to an implementation-defined value, or - A pointer to the allocated space shall be returned. The application shall ensure that the pointer is not used to access an object. π
Otherwise, it shall return a null pointer and set errno to indicate the error.
π ERRORS π
The malloc() function shall fail if:
ENOMEMβ Insufficient storage space is available. π bestie the memory is gone.
The following sections are informative.
π EXAMPLES π
None. (yeah, nothing. iconic of it honestly π )
π¦ APPLICATION USAGE π¦
None.
π RATIONALE π
None.
β FUTURE DIRECTIONS β
None.
π SEE ALSO π
calloc(), free(), getrlimit(), posix_memalign(), realloc()
The Base Definitions volume of POSIX.1β2017, <stdlib.h>
π§ COPYRIGHT π§
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
and that's the whole page, bestie πβ¨ slay, you now understand malloc better than half the people writing it. this iconic lil page came from IEEE/The Open Group, 2017. go allocate something responsibly. ππ«Ά
π¦ where this page comes from
- debian bookworm: manpages-posix-dev 2017a-2 Β· Other
- debian trixie: manpages-posix-dev 2017a-2 Β· Other
- ubuntu jammy: manpages-posix-dev 2017a-2 Β· Other
- ubuntu noble: manpages-posix-dev 2017a-2 Β· Other
- ubuntu resolute: manpages-posix-dev 2017a-2build1 Β· Other
- ubuntu stonking: manpages-posix-dev 2017a-2.1 Β· Other
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms