memalign(3)
β¨ memalign β memory aligned allocate β¨
Okay bestie, we're in section 3 of the manual (that's library functions, iykyk), and today's main character is memalign() π
π LIBRARY
Standard C library β link it in with libc, -lc π«Ά
π SYNOPSIS
#include <malloc.h>
[[deprecated]] void *memalign(size_t alignment, size_t size);
Not me pointing at that [[deprecated]] β bestie, it's right there in the signature, the compiler is literally telling you. π
π¦ DESCRIPTION
So memalign() is equivalent to aligned_alloc(3) β like, same energy, same job β except for the CAVEATS documented down below. Don't skip those, fr fr. π
πΈ ATTRIBUTES
Wanna know what all these fancy words in this section even mean? Go peek at attributes(7) π
Here's the tea on memalign():
- Interface:
memalign() - Attribute: Thread safety
- Value:
MT-Safeπ
So yeah, it's thread-safe, slay.
π VERSIONS
Plot twist π β on some systems, memalign() is declared in <stdlib.h> instead of <malloc.h>. So if your include isn't giving, check the other one, bestie.
β STANDARDS
None. Literally none. It's giving "no standard, just vibes." π«
π HISTORY
glibc 2.0SunOS 4.1.3
Ancient. Iconic. Been here since forever. ποΈ
β οΈ CAVEATS
Okay this is the part where we get serious for a sec, bestie, because these are real.
memalign()may not check that thealignmentargument is correct. So likeβ¦ it might just not verify it. Be careful what you hand it. π- On some systems, there is no way to reclaim memory allocated with
memalign(). Why? Because you can only pass tofree(3)a pointer that came frommalloc(3)β and, for example,memalign()would callmalloc(3)and then align the value it got back. Different pointer, sofree(3)can't touch it. π - The glibc implementation, though? It does let memory obtained from
memalign()be reclaimed withfree(3). So you're good there. π«Ά
π SEE ALSO
This page is from Linux man-pages 6.20, dated 2026-07-26, and it's for memalign(3). That's the whole thing, bestie β go forth and align your memory responsibly ππβ¨
π¦ where this page comes from
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- π the page's license: Linux-man-pages-copyleft
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms