MySQL内存池结构源码 my_alloc.h

 

MySQL使用内存池结构,理解该结构挺简单的,但是对于my_alloc.c中的分配过程感觉上很难理解。

/*

   Data structures for mysys/my_alloc.c (root memory allocator)

*/

 

#ifndef _my_alloc_h

#define _my_alloc_h

 

#define ALLOC_MAX_BLOCK_TO_DROP                      4096

#define ALLOC_MAX_BLOCK_USAGE_BEFORE_DROP    10

 

#ifdef __cplusplus

extern "C" {

#endif

 

//内存链表

typedef struct st_used_mem

{                                      /* struct for once_alloc (block) */

  struct st_used_mem *next;      /* Next block in use */

  unsigned int  left;              /* memory left in block  */

  unsigned int  size;              /* size of block */

} USED_MEM;

 

//链表首地址,分别维护空闲、使用和预分配的内存

typedef struct st_mem_root

{

  USED_MEM *free;                  /* blocks with free memory in it */

  USED_MEM *used;                  /* blocks almost without free memory */

  USED_MEM *pre_alloc;             /* preallocated block */

  /* if block have less memory it will be put in 'used' list */

  size_t min_malloc;

  size_t block_size;               /* initial block size */

  unsigned int block_num;          /* allocated blocks counter */

  /*

     first free block in queue test counter (if it exceed

     MAX_BLOCK_USAGE_BEFORE_DROP block will be dropped in 'used' list)

  */

  unsigned int first_block_usage;

 

  void (*error_handler)(void);

} MEM_ROOT;

 

#ifdef  __cplusplus

}

#endif

 

#endif

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值