How does free(ptr) in C know how much memory to release when you never pass it the…
This is a dev post classified by AGK Intelligence as Languages & runtimes (a tutorial), kept by the Dev Radar because it carries real work, not commentary.
How does free(ptr) in C know how much memory to release when you never pass it the allocation size? On glibc, malloc() keeps a hidden chunk header immediately before the pointer it returns. One word stores the chunk size, with the lowest three bits used as allocator flags. When you call free(ptr), glibc recovers that metadata. The size was never lost. It was simply hidden from your program. You can inspect the allocator’s usable size with the GNU-specific malloc_usable_size() function:
Posted by Strace (10.7k followers) 2 h ago · 22 likes · 617 views · view the original post on X. Kept by the Dev Radar as Languages & runtimes.
More dev work like this
- Explore the details of a Sequenced Map with @JosePaumard in this Java Coding Tip. — @java
- Yo, PLT nerds @Jay59009444 just dropped… — @GeoffreyHuntley
- また別の自作 wasm 言語を試作してる。 — @mizchi
- My talk at @golab_conf last October is now available on Youtube. — @raphamorims
- #Python #DataScience! #BigData #Analytics #DataScience #AI #MachineLearning #IoT #IIoT… — @gp_pulipaka
- Prime functions in Python! BigData #Analytics #DataScience #AI #MachineLearning #IoT… — @gp_pulipaka
- javascript esoterica. — @xah_lee
- rust crate for fff was downloaded quarter million times — @neogoose_btw
Every post is read and classified by AGK Intelligence: what it is, which market it belongs to, and whether the link is a real tool. 31.8k posts from 5k X accounts over the last 21 days, 9.4k tools, 12 markets. New posts are collected several times an hour and the full ranking is recomputed every hour — last update 2026-11-05 23:17 UTC. Full method.