ptmalloc算法chunk简介

本文主要介绍内存管理算法ptmalloc的内存管理单位–chunk的基本知识。

内存管理算法ptmalloc

内存分配的最小单位chunk

chunk数据结构在glibc-2.31源码中的定义如下:

/*
  This struct declaration is misleading (but accurate and necessary).
  It declares a "view" into memory allowing access to necessary
  fields at known offsets from a given base. See explanation below.
*/

struct malloc_chunk {

  INTERNAL_SIZE_T      mchunk_prev_size;  /* Size of previous chunk (if free).  */
  INTERNAL_SIZE_T      mchunk_size;       /* Size in bytes, including overhead. */

  struct malloc_chunk* fd;         /* double links -- used only if free. */
  struct malloc_chunk* bk;

  /* Only used for large blocks: pointer to next larger size.  */
  struct malloc_chunk* fd_nextsize; /* double links -- used only if free. */
  struct malloc_chunk* bk_nextsize;
};

gdb查看chunk的内容

了解chunk的意义

参考资料

你可能感兴趣的:(ptmalloc)