malloc_usable_size(3)
π malloc_usable_size(3) π
okay so bestie, we're in the Library Functions Manual today and the star of the show is malloc_usable_size β yes that's the manual section 3 one, the library-call girlies. lets GO π¦
β¨ NAME β¨
malloc_usable_size β obtain size of block of memory allocated from heap
π LIBRARY π
Standard C library (libc, -lc)
π SYNOPSIS π
#include <malloc.h>
size_t malloc_usable_size(void *_Nullable ptr);
πΈ DESCRIPTION πΈ
So like. This function is your little detective π΅οΈβοΈ bestie. You can use it for diagnostics or statistics about allocations that came from malloc(3) or one of its related functions.
That's it. That's the whole job. It's giving β¨informationalβ¨, not β¨functionalβ¨. iykyk.
π₯ RETURN VALUE π₯
malloc_usable_size() returns a value no less than the size of the block of allocated memory pointed to by ptr.
And if ptr is NULL? You get 0 back. no drama, no crash, just a lil zero π«Ά
π ATTRIBUTES π
(if you wanna know what any of these words even mean, go read attributes(7), she explains it all)
- Interface:
malloc_usable_size()- Attribute: Thread safety
- Value:
MT-Safe
slay, she's MT-Safe, you can call her from multiple threads, she's not gonna start anything π
π STANDARDS π
GNU. (periodt.)
π CAVEATS π
okay bestie this is the part where you LISTEN TO ME because this is the important bit π¨
- The value returned by
malloc_usable_size()may be greater than the requested size of the allocation, because of various internal implementation details β and none of which the programmer should rely on. like. none. zero. not one. π - This function is intended to only be used for diagnostics and statistics.
- Writing to the excess memory without first calling
realloc(3)to resize the allocation is not supported. NOT supported. do not do it. do not pass go. do not collect $200. π - The returned value is only valid at the time of the call. it's a snapshot, a lil polaroid πΈ, not a promise about the future.
fr fr, treat this number like a gossip girl told you β interesting, maybe useful for your stats, absolutely not something you build a house on. π π
π SEE ALSO π
and that's the whole page bestie!! this one came from Linux man-pages 6.20, dated 2026-02-08, and it's the malloc_usable_size(3) page π you ate that, go write some diagnostics π
π¦ 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
- Copyright 2012, Michael Kerrisk <mtk.manpages@gmail.com>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms