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.0
  • SunOS 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 the alignment argument 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 to free(3) a pointer that came from malloc(3) β€” and, for example, memalign() would call malloc(3) and then align the value it got back. Different pointer, so free(3) can't touch it. πŸ’€
  • The glibc implementation, though? It does let memory obtained from memalign() be reclaimed with free(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