内存池的处理
pool->sector->blocks
pool is organized as sectors , and new sectors ared added when there is more blocks needed.
mem_block_creat_pool(zg, blk_size , no_of_block,no_of_sectors)
点击查看代码
no_of_blocks :no_of_blocks per sector
no_of_sectors:max nomber _of_sectors per pool, if 0, the pool will creat as many of sectors as the system could afford .
return : pointer to a pool management instance
mem_block_creat_pool(zg, blk_size , no_of_blocks, no_of_sectors)
{
adjusted_blk_size = (blk_size + 7) & ~(7);//内存对齐
total_size = no_of_blocks * adjusted_blk_size;
if (no_of_blocks >= UINT_MAX/2 || no_of_blocks * no_of_sectors >= UINT_MAX/2 )
return ERROR;
pool = malloc (sizeof (mem_blk_pool_t));
memset(pool,0,sizeof (mem_blk_pool_t));
pool->zg = zg;
pool->blk_size = blk_size;
pool->adjusted_blk_size = adjusted_blk_size
pool->toal_size = toal_size;
pool->no_of_blks= no_of_blocks;
pool->no_of_scts= no_of_scts;
pool->sectors= vertor_innit(no_of_sectors);
//创建AVL树,每一个节点先从freelist 申请,再从系统内存中申请
pal_avl_creat_mem_blk(&pool->sectors_tree,0,cpmare_func)
}
本文来自博客园,作者:开源侠,转载请注明原文链接:https://www.cnblogs.com/cyj22/p/17899498.html
微信公众号:青衫换酒吃