Deepin Linux
Deepin Linux
Mar 5, 2026 · Fundamentals

Unveiling malloc: How C Allocates Memory Behind the Scenes

This comprehensive guide explains the inner workings of the C malloc function, covering memory layout, stack vs heap, glibc memory pools, system calls like brk/sbrk and mmap, allocation strategies, fragmentation, alignment, multithreading safety, and comparisons with calloc, realloc, and C++ new.

C programmingglibcheap management
0 likes · 53 min read
Unveiling malloc: How C Allocates Memory Behind the Scenes
Liangxu Linux
Liangxu Linux
Aug 19, 2025 · Fundamentals

How malloc and free Work: Inside Dynamic Memory Allocation

This article explains the fundamentals of malloc and free, covering their signatures, how they interact with the brk/sbrk system calls, the structure of memory control blocks, multiple allocation strategies such as explicit free lists, segregated lists, buddy systems and tcmalloc, along with code examples and their trade‑offs.

C programmingFreedynamic memory
0 likes · 15 min read
How malloc and free Work: Inside Dynamic Memory Allocation
Liangxu Linux
Liangxu Linux
Apr 2, 2025 · Fundamentals

How Does malloc Actually Work? Inside a Simple Memory Allocator

This article explains why dynamic memory allocation is essential, models the heap as a parking lot, outlines the core challenges of implementing malloc and free, describes block headers, explores First Fit, Next Fit, and Best Fit strategies, and details splitting, internal fragmentation, and efficient coalescing using footers.

FragmentationSystems Programmingallocation strategies
0 likes · 17 min read
How Does malloc Actually Work? Inside a Simple Memory Allocator