函数mem_area_alloc
/********************************************************************//**
Allocates memory from a pool. NOTE: This low-level function should only be
used in mem0mem.*!
@return own: allocated memory buffer */
UNIV_INTERN
void*
mem_area_alloc(
/*===========*/
ulint* psize, /*!< in: requested size in bytes; for optimum
space usage, the size should be a power of 2
minus MEM_AREA_EXTRA_SIZE;
out: allocated size in bytes (greater than
or equal to the requested size) */
mem_pool_t* pool) /*!< in: memory pool */
{
mem_area_t* area;
ulint size;
ulint n;
ibool ret;
/* If we are using os allocator just make a simple call
to malloc */
if (UNIV_LIKELY(srv_use_sys_malloc)) {
return(malloc(*psize));
}
size = *psize;
n = ut_2_log(ut_max(size + MEM_AREA_EXTRA_SIZE, MEM_AREA_MIN_SIZE));
mutex_enter(&(pool->mutex));
mem_n_threads_inside++;
ut_a(mem_n_threads_inside == );
area = UT_LIST_GET_FIRST(pool->free_list[n]);
if (area == NULL) { /** *详见
*pool->free_list[i]找不到内存块的话,尝试从pool->free_list[i+1]中查找 *如果找不到,一直向上查找 * *如果找到了,从list列表中摘除,并插入到向下的数组元素所在列表中 * *例如:要分配100字节内存,通过计算在pool->free_list[7]中查找 2^7=128 而 2^6=64不符合要求 *如果pool->free_list[7]的头结点为空, *那么从pool->free_list[7+1]中查找并赋值为area,如果找到,将area从pool->free_list[8]中的链表中删除 *将此area取类型强制转为byte*,然后取(byte*)area+ut_2_exp(7) 即取出area一半的地址 *再设置size为ut_2_exp(7) *并设置为pool->free_list[7]的头结点
*/
ret = mem_pool_fill_free_list(n, pool);
if (ret == FALSE) {
/* Out of memory in memory pool: we try to allocate
from the operating system with the regular malloc: */
mem_n_threads_inside--;
mutex_exit(&(pool->mutex));
return(ut_malloc(size));
}
//此area为合适的内存块
area = UT_LIST_GET_FIRST(pool->free_list[n]);
}
/** *判断此area是否是空闲的,false为已使用 *area->size_and_free & MEM_AREA_FREE */
if (!mem_area_get_free(area)) {
fprintf(stderr,
"InnoDB: Error: Removing element from mem pool"
" free list %lu though the\n"
"InnoDB: element is not marked free!\n",
(ulong) n);
mem_analyze_corruption(area);
/* Try to analyze a strange assertion failure reported at
mysql@lists.mysql.com where the free bit IS 1 in the
hex dump above */
if (mem_area_get_free(area)) {
fprintf(stderr,
"InnoDB: Probably a race condition"
" because now the area is marked free!\n");
}
ut_error;
}
) {
fprintf(stderr,
"InnoDB: Error: Removing element from mem pool"
" free list %lu\n"
"InnoDB: though the list length is 0!\n",
(ulong) n);
mem_analyze_corruption(area);
ut_error;
}
ut_ad(mem_area_get_size(area) == ut_2_exp(n));
/** *设置为已使用状态 *并从pool->free_list[n]中删除头结点 */
mem_area_set_free(area, FALSE);
UT_LIST_REMOVE(free_list, pool->free_list[n], area);
pool->reserved += mem_area_get_size(area);
mem_n_threads_inside--;
mutex_exit(&(pool->mutex));
ut_ad(mem_pool_validate(pool));
*psize = ut_2_exp(n) - MEM_AREA_EXTRA_SIZE;
UNIV_MEM_ALLOC(MEM_AREA_EXTRA_SIZE + (byte*)area, *psize);
return((void*)(MEM_AREA_EXTRA_SIZE + ((byte*)area)));
}
函数mem_area_alloc的更多相关文章
- Python 小而美的函数
python提供了一些有趣且实用的函数,如any all zip,这些函数能够大幅简化我们得代码,可以更优雅的处理可迭代的对象,同时使用的时候也得注意一些情况 any any(iterable) ...
- 探究javascript对象和数组的异同,及函数变量缓存技巧
javascript中最经典也最受非议的一句话就是:javascript中一切皆是对象.这篇重点要提到的,就是任何jser都不陌生的Object和Array. 有段时间曾经很诧异,到底两种数据类型用来 ...
- JavaScript权威指南 - 函数
函数本身就是一段JavaScript代码,定义一次但可能被调用任意次.如果函数挂载在一个对象上,作为对象的一个属性,通常这种函数被称作对象的方法.用于初始化一个新创建的对象的函数被称作构造函数. 相对 ...
- C++对C的函数拓展
一,内联函数 1.内联函数的概念 C++中的const常量可以用来代替宏常数的定义,例如:用const int a = 10来替换# define a 10.那么C++中是否有什么解决方案来替代宏代码 ...
- 菜鸟Python学习笔记第一天:关于一些函数库的使用
2017年1月3日 星期二 大一学习一门新的计算机语言真的很难,有时候连函数拼写出错查错都能查半天,没办法,谁让我英语太渣. 关于计算机语言的学习我想还是从C语言学习开始为好,Python有很多语言的 ...
- javascript中的this与函数讲解
前言 javascript中没有块级作用域(es6以前),javascript中作用域分为函数作用域和全局作用域.并且,大家可以认为全局作用域其实就是Window函数的函数作用域,我们编写的js代码, ...
- 复杂的 Hash 函数组合有意义吗?
很久以前看到一篇文章,讲某个大网站储存用户口令时,会经过十分复杂的处理.怎么个复杂记不得了,大概就是先 Hash,结果加上一些特殊字符再 Hash,结果再加上些字符.再倒序.再怎么怎么的.再 Hash ...
- JS核心系列:浅谈函数的作用域
一.作用域(scope) 所谓作用域就是:变量在声明它们的函数体以及这个函数体嵌套的任意函数体内都是有定义的. function scope(){ var foo = "global&quo ...
- C++中的时间函数
C++获取时间函数众多,何时该用什么函数,拿到的是什么时间?该怎么用?很多人都会混淆. 本文是本人经历了几款游戏客户端和服务器开发后,对游戏中时间获取的一点总结. 最早学习游戏客户端时,为了获取最精确 ...
随机推荐
- 为什么V8引擎这么快?(转载)
转载请注明出处:http://blog.csdn.net/horkychen Google研发的V8 JavaScript引擎性能优异.我们请熟悉内部程序实现的作者依源代码来看看V8是如何加速的. 作 ...
- 初涉Node.js
Node.js的是建立在Chrome的JavaScript的运行时,可方便地构建快速,可扩展的网络应用程序的平台. Node.js使用事件驱动.非阻塞I/ O模型,是轻量级.高效.完美的跨分布式设备运 ...
- Discuz!NT3.6与网站整合(操作用户信息)解决方案
因为网站要加个论坛,所以就用到了Discuz!NT3.6. 可惜目前官方论坛已经关闭,只有3.6版本的有源码,3.9的没有源码,不好操作,下载地址: http://download.comsenz.c ...
- C#WinForm中在dataGridView中添加中文表头
第一步: 注意事项:(1)如果使用数据库,那么第三步的名称可以是任意的,但是不能和数据库中的列名一样,否则会报错: (2)第四步的页眉文本就是你想用的中文列名,自己定: (3)第六步尤其重要,不 ...
- 1502: [NOI2005]月下柠檬树 - BZOJ
Description Input 文件的第1行包含一个整数n和一个实数alpha,表示柠檬树的层数和月亮的光线与地面夹角(单位为弧度).第2行包含n+1个实数h0,h1,h2,…,hn,表示树离地的 ...
- Code First 中的 TPH TPT TPC
public class Blog { public int Id { get; set; } public DateTime Creationdate { get; set; } public st ...
- setblendstate & setdepthstencilstate
http://msdn.microsoft.com/en-us/library/windows/desktop/ff476462(v=vs.85).aspx blendstate blendfacto ...
- Codeforces Round #363 (Div. 2)->A. Launch of Collider
A. Launch of Collider time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- 判断不同IOS设备
var iOSGen = iPhone.generation; if (Debug.isDebugBuild) { Debug.Log("iPhone.generation : " ...
- crawler
# !/usr/bin/env python# encoding:UTF-8from util import request_urlimport reimport osimport sys#from ...