valloc(3)

✨ valloc(3) ✨

okay bestie, pull up a chair because we're talking about valloc from the Library Functions Manual and honestly? she's a legacy icon but she's also kinda retired, so let's get into it πŸ’…


NAME πŸŽ€

valloc β€” page-aligned memory allocation

no cap, that's literally the whole job. she hands you memory, but the address is all fancy and page-aligned ✨


LIBRARY πŸ¦‹

Standard C library β€” link it with -lc, bestie. as usual 🫢


SYNOPSIS 🌸

#include <stdlib.h>

[[deprecated]] void *valloc(size_t size);

see that [[deprecated]]? yeah. she's marked. the compiler is gonna side-eye you. it's giving "we still support her but we're not happy about it" πŸ’€

Feature Test Macro Requirements for glibc πŸ’œ

(if you need the full lore on these, go read feature_test_macros(7), she explains everything)

valloc():
    Since glibc 2.12:
        (_XOPEN_SOURCE >= 500) && !(_POSIX_C_SOURCE >= 200112L)
            || /* glibc >= 2.19: */ _DEFAULT_SOURCE
            || /* glibc <= 2.19: */ _SVID_SOURCE || _BSD_SOURCE
    Before glibc 2.12:
        _BSD_SOURCE || _XOPEN_SOURCE >= 500

okay so the way that you get her declared is very glibc-version-dependent, so check your macros before you start crying about implicit declarations 😭


DESCRIPTION πŸ’–

so valloc() allocates size bytes and hands back a pointer to that allocated memory. but here's the flex: the memory address is gonna be a multiple of the page size. every time. no exceptions. main character alignment energy πŸ‘‘

she's literally equivalent to:

memalign(sysconf(_SC_PAGESIZE),size)

same thing, different font. periodt.


ATTRIBUTES ⭐

if you're confused about what "attributes" even means here, attributes(7) has you covered, bestie.

  • Interface: valloc()
  • Attribute: Thread safety
  • Value: MT-Unsafe init

so... not thread safe on init. be careful out there πŸ™ˆ


VERSIONS 🌈

okay so per SUSv2, valloc() is declared in <stdlib.h>.

glibc, being extra, declares it in <malloc.h> β€” and also in <stdlib.h>, but only if you've defined the right feature test macros (scroll up, they're right there ✨).


STANDARDS πŸ“

BSD, GNU.

that's the whole list. she's a two-house icon πŸ’…


HISTORY πŸŽ€

  • glibc 2.0.
  • 3.0BSD.
  • Documented as obsolete in 4.3BSD πŸ’€
  • Documented as legacy in SUSv2

so yeah, she's been around for a minute, and the docs have been gently roasting her basically the entire time. iconic behaviour honestly 🫢


CAVEATS πŸ”₯

go look at memalign(3). that's where the real warnings live, bestie. don't skip it πŸ‘€


SEE ALSO πŸ¦‹


and that's the whole page, bestie!! mwah πŸ’–

this little time capsule comes to you from Linux man-pages 6.20, dated 2025-12-13, and yes she's still filed under valloc(3) after all these years β€” legacy queen, we love her πŸ‘‘βœ¨

πŸ“¦ 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