Chinaunix首页 | 论坛 | 博客
  • 博客访问: 380925
  • 博文数量: 82
  • 博客积分: 1855
  • 博客等级: 上尉
  • 技术积分: 846
  • 用 户 组: 普通用户
  • 注册时间: 2010-09-12 12:28
文章存档

2013年(3)

2012年(8)

2011年(71)

分类: C/C++

2011-11-05 23:52:16

  1. #include <malloc.h>
  2. int mallopt (int param, int value)param的取值分别为M_MXFAST。value是以字节为单位。
  3. M_MXFAST :定义fastbins的小块内存阀值,小于该阀值的小块空闲内存将不会去尝试合并,其缺省值为64。
  4. 下面我们来将M_MXFAST设置为0,禁止掉fastbins,使其跟踪每一个小块内存并尝试进行合并。
  5. #include <stdlib.h>
  6. #include <stdio.h>
  7. #include <malloc.h>
  8. int main()
  9. {
  10.   //mallopt(M_MXFAST,0);
  11.     char *p=malloc(20);
  12.     char *p1=malloc(10);
  13.     char *p2=malloc(20);
  14.     printf("%p %p %p\n",p,p1,p2);
  15.     free(p);
  16.     free(p1);
  17.     char *p3=malloc(20);
  18.     printf("%p\n",p3);
  19.     return 0;
  20. }

  21. 我们来看下结果:
  22. # ./hello
  23. 0x11050 0x11060 0x11070
  24. 0x11050
阅读(4631) | 评论(0) | 转发(0) |
0

上一篇:代码简化呀fork

下一篇:使用find和xargs

给主人留下些什么吧!~~