{
  "id": 19154484,
  "title": "What is malloc doing, anyway?",
  "url": "https://urgent.news/2026/11/09/what-is-malloc-doing-anyway",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-11-09T13:19:22.000Z",
  "source": {
    "name": "Lobsters",
    "slug": "lobsters",
    "url": "https://benmandrew.com/articles/what-is-malloc-doing-anyway"
  },
  "original_language": "en",
  "account": "The malloc function provides a simple interface for requesting blocks of memory. When you call malloc with a specific size, it returns a void pointer to a contiguous block of bytes that has been created for your use. Once you no longer need that memory, you call free with the same pointer, and the memory is freed up again.\n\nUnder the hood, malloc relies on the kernel through syscalls to actually allocate and free memory. However, making a syscall for every small allocation can be expensive. To mitigate this, malloc performs some bookkeeping in the background.\n\nWhen you call malloc repeatedly in a loop, like a thousand times, malloc doesn't go through the kernel each time. Instead, it first asks the kernel for a larger block of memory using the brk syscall, which sets the program break to the requested address, effectively allocating the heap. Subsequent calls to malloc simply take memory from this existing block, without needing to go through brk again.\n\nmalloc also allocates a little extra memory beyond what you requested, to accommodate the bookkeeping metadata it needs to manage the allocations and deallocations. The memory returned by malloc is also aligned to a 16-byte boundary, which is suitable for any C data type.\n\nWhen you free a chunk of memory, malloc puts it into a free list so that it can be reused for future allocations. It tries to merge adjacent free chunks back together to reduce fragmentation and make more efficient use of memory.\n\nThis behind-the-scenes bookkeeping makes malloc much more efficient than a naive allocator that simply bumps a pointer up by the requested size each time. malloc defers the expensive syscalls until necessary, and reuses memory whenever possible.",
  "summary": null,
  "key_points": [
    "Malloc provides simple interface for requesting memory blocks.",
    "It relies on kernel for allocation and free operations.",
    "Malloc performs bookkeeping to reuse memory efficiently."
  ],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}