博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
stdlib中的xmalloc,xfree,xinit_mempool
阅读量:2436 次
发布时间:2019-05-10

本文共 3588 字,大约阅读时间需要 11 分钟。

1.xinit_mempool

 

Summary
#include 
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 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.
Return Value

None.

See Also

, , ,

Example
#include 
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 
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 pointers to objects and may be used in any memory model other than Tiny Model.
Return Value

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 Also

, , ,

Example
#include 
#include
/* 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 
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 pointers to objects and may be used in any memory model other than Tiny Model.
Return Value

None.

See Also

, , ,

Example
#include 
#include
/* 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://qxgmb.baihongyu.com/

你可能感兴趣的文章
PostgreSQL 源码解读(48)- 查询语句#33(query_planner函数#9)
查看>>
PostgreSQL 源码解读(45)- 查询语句#30(query_planner函数#6)
查看>>
PostgreSQL 源码解读(47)- 查询语句#32(query_planner函数#8)
查看>>
PostgreSQL 源码解读(17)- 查询语句#2(查询优化基础)
查看>>
Windows Vista内置趣味实用工具大搜罗(转)
查看>>
FreeBSD安装文件系统(转)
查看>>
最简单FreeBSD网关方案(转)
查看>>
Windows 98 多用户的管理(转)
查看>>
更改Windows XP 的日期和时间(转)
查看>>
windows2000中的“秘密武器”(三)(转)
查看>>
Linux程序应用开发环境和工具经验谈(转)
查看>>
Linux办公一条龙之电子表格Calc(转)
查看>>
在NETBSD上配置ADSL+IPF+IPNAT(转)
查看>>
Windows 98 使用维护向导(转)
查看>>
用win2000收发传真(转)
查看>>
Linux办公一条龙之初识OpenOffice(转)
查看>>
Linux上安装GCC编译器过程(转)
查看>>
使用Windows XP 的任务计划(转)
查看>>
FreeBSD软盘操作(转)
查看>>
Linux分区工具的使用方法(转)
查看>>