sbrk and coreleft

一、sbrk

函数来源:TC2.0、Linux

函数名: sbrk
功 能: 增加程序可用数据段空间,增加大小由参数 incr决定 。
返回值:函数调用成功返回一指针,指向新的内存空间。函数调用失败则返回 -1,将errno设为ENOMEM。
函数原型:
  void * _Cdecl sbrk(int incr)(摘自TC2.0中的alloc.h)
  void * sbrk(intptr_t __delta) __THROW;(摘自Ubuntu中的usr/include/unistd.h)
注意:此函数在VC6.0中并没有找到。
二、coreleft
函数来源:TC2.0
函数名: coreleft
功 能: 返回未使用内存的大小
返回值:未使用内存的大小
函数原型:
   unsigned long coreleft(void);(摘自TC2.0的alloc.h)
注意:此函数在VC6.0以及Ubuntu的gcc中均没有找到。
三、测试
1、测试环境
  编译器: TC2.0
2、测试代码
#include <stdio.h>
#include <alloc.h>
int main(void)
{
    printf("Changing allocation with sbrk()
");
    printf("Before sbrk() call: %lu bytes free
", (unsigned long) coreleft());
    sbrk(1000);
    printf(" After sbrk() call: %lu bytes free
",(unsigned long) coreleft());
    return 0;
}  

 3、运行结果

原文地址:https://www.cnblogs.com/amanlikethis/p/3764600.html