stdlib中的xmalloc,xfree,xinit_mempool
来源:互联网 发布:淘宝首页尺寸大小 编辑:程序博客网 时间:2024/05/18 00:33
1.xinit_mempool
Summary
#include <stdlib.h>void xinit_mempool ( void xhuge *p, /* start of memory pool */ unsigned long size); /* length of memory pool */Description
The xinit_mempool function initializes the memory management routines and provides the starting address and size of the memory pool. The p argument points to a memory area in xdata which is managed using the xcalloc, xfree, xmalloc, and xrealloc library functions. The size argument specifies the number of bytes to use for the memory pool.
Note
- This function must be used to setup the memory pool before any other memory management functions (xcalloc, xfree, xmalloc, xrealloc) can be called. Call the xinit_mempool function only once at the beginning of your program.
- Source code for this routine is provide in the LIB folder. You may modify the source to customize this function for your particular hardware environment.
- This function uses xhuge pointers to objects and may be used in any memory model other than Tiny Model.
- Each memory block needs 8 bytes overhead to handle the allocation information. In addition another 8 bytes are required for init_mempool itself. Therefore if you want to allocate 2 blocks with 100 bytes each, the memory pool size must be 224 bytes.
None.
See Alsoxcalloc, xfree, xmalloc, xrealloc
Example#include <stdlib.h>void tst_init_mempool (void) { xdata void *p; int i;/* initialize memory pool at xdata 0x2000 for 4096 bytes */ xinit_mempool (&XBYTE [0x2000], 0x1000); p = xmalloc (100); for (i = 0; i < 100; i++) ((char *) p)[i] = i; xfree (p);}
2.xmalloc
Summary
#include <stdlib.h>void xhuge *xmalloc ( unsigned long size); /* block size to allocate */Description
The xmalloc function allocates a memory block from the memory pool of size bytes in length.
Note
- Source code for this routine is provide in the LIB folder. You may modify the source to customize this function for your particular hardware environment.
- This function uses xhuge pointers to objects and may be used in any memory model other than Tiny Model.
The xmalloc function returns a pointer to the allocated block or a null pointer if there is not enough memory to satisfy the allocation request.
See Alsoxcalloc, xfree, xinit_mempool, xrealloc
Example#include <stdlib.h>#include <stdio.h> /* for printf */void tst_malloc (void) { void xhuge *p; p = xmalloc (1000); /* allocate 1000 bytes */ if (p == NULL) printf ("Not enough memory space/n"); else printf ("Memory allocated/n");
3.xfree
Summary#include <stdlib.h>void xfree ( void xhuge *p); /* block to free */Description
The xfree function returns a memory block to the memory pool. The p argument points to a memory block that was previously allocated with the xcalloc, xmalloc, or xrealloc functions. Once it has been returned to the memory pool by the free function, the block is available for subsequent allocation.
If p is a null pointer, it is ignored.
Note
- Source code for this routine is provide in the LIB folder. You may modify the source to customize this function for your particular hardware environment.
- This function uses xhuge pointers to objects and may be used in any memory model other than Tiny Model.
None.
See Alsoxcalloc, xinit_mempool, xmalloc, xrealloc
Example#include <stdlib.h>#include <stdio.h> /* for printf */void tst_free (void) { void xhuge *mbuf; printf ("Allocating memory/n"); mbuf = xmalloc (1000); if (mbuf == NULL) { printf ("Unable to allocate memory/n"); } else { xfree (mbuf); printf ("Memory free/n"); }}
C166 User's Guid http://www.keil.com/support/man/docs/c166/c166_intro.htm
- stdlib中的xmalloc,xfree,xinit_mempool
- STDLIB
- 关于STDLIB.H头文件中的函数应用
- 关于stdlib
- stdlib.h
- stdlib.h
- <stdlib.h>
- "stdlib.h"
- stdlib.h
- stdlib.h
- stdlib.h
- stdlib.h
- stdlib.h
- <stdlib.h>中的随机数产生函数rand,random,srand,srandom的一些知识
- C语言学习:简单了解下stdlib中的字符串转换函数
- X11 XFREE WM KDE GNOME xorg概念
- X11 XFREE WM KDE GNOME xorg
- C语言stdlib库(#include<stdlib.h>)
- 面向对象的三个基本特征详解
- 深入理解JavaScript闭包(closure)
- 插入排序
- 递归目录的所有文件
- PD12逆向工程从Oracle10中生成,出现ORA-00942 表或者视图不存在错误
- stdlib中的xmalloc,xfree,xinit_mempool
- Mcafee virusScan Enterprise 8.5.0i 与 javaMail 问题
- MAC MINI的CPU类型
- PHP学习笔记
- IT的职场法则
- 如何把DataGridView中的数据导入Excel
- 云计算的主要应用
- 做个DataList 可分页的数据源
- jQuery小功能总结