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
#endifMySQL中JOIN查询详解MySQL 从接收连接到执行连接命令的一个源码流程相关资讯 MySQL教程
- 30分钟带你快速入门MySQL教程 (02月03日)
- MySQL教程:关于I/O内存方面的一些 (01月24日)
- CentOS上开启MySQL远程访问权限 (01/29/2013 10:58:40)
| - MySQL教程:关于checkpoint机制 (01月24日)
- MySQL::Sandbox (04/14/2013 08:03:38)
- 生产环境MySQL 5.5.x单机多实例配 (11/02/2012 21:02:36)
|
本文评论 查看全部评论 (0)