📄 alloc.h
字号:
@函数名称: brk
函数原型: int brk(void *eds)
函数功能: 改变数据段所用内存的数量
函数返回:
参数说明:
所属文件: <alloc.h>
#include <stdio.h>
#include <alloc.h>
int main()
{
char *ptr;
printf("Changing allocation with brk()");
ptr=malloc(1);
printf("Before brk() call: %lu bytes free",coreleft());
brk(ptr+1000);
printf(" After brk() call: %lu bytes free",coreleft());
return 0;
}
@函数名称: coreleft
函数原型: unsigned coreleft(void)-小模式;long coreleft(void)-大模式
函数功能: 得到heap内存中的剩余字节数
函数返回: 剩余字节数
参数说明:
所属文件: <alloc.h>
#include <stdio.h>
#include <alloc.h>
int main()
{
printf("The difference between the highest allocated block and");
printf("the top of the heap is: %lu bytes",(unsigned long) coreleft());
return 0;
}
@函数名称: farcalloc
函数原型: void far *farcalloc(unsigned long num, unsigned long size)
函数功能: 从远堆中分配内存块
函数返回: 已分配的内存块指针
参数说明: num,size 分配内存的字节数:num*size
所属文件: <alloc.h>
#include <stdio.h>
#include <alloc.h>
#include <string.h>
#include <dos.h>
int main()
{
char far *fptr;
char *str="Hello";
fptr=farcalloc(10, sizeof(char));
movedata(FP_SEG(str), FP_OFF(str),
FP_SEG(fptr), FP_OFF(fptr),strlen(str));
printf("Far string is: %Fs", fptr);
farfree(fptr);
return 0;
}
@函数名称: farcoreleft
函数原型: long farcoreleft(void)
函数功能: 得到远堆中的剩余内存字节数
函数返回: 剩余字节数
参数说明:
所属文件: <alloc.h>
#include <stdio.h>
#include <alloc.h>
int main()
{
printf("The difference between the highest allocated block in the far");
printf("heap and the top of the far heap is: %lu bytes", farcoreleft());
return 0;
}
@函数名称: farfree
函数原型: void farfree(void far *ptr)
函数功能: 释放由farmalloc()和faralloc()分配的内存
函数返回:
参数说明: ptr 被释放的指针
所属文件: <alloc.h>
#include <stdio.h>
#include <alloc.h>
#include <string.h>
#include <dos.h>
int main()
{
char far *fptr;
char *str="Hello";
fptr=farcalloc(10, sizeof(char));
movedata(FP_SEG(str), FP_OFF(str),FP_SEG(fptr), FP_OFF(fptr),strlen(str));
printf("Far string is: %Fs", fptr);
farfree(fptr);
return 0;
}
@函数名称: farmalloc
函数原型: far *farmalloc(unsigned long size)
函数功能: 从远堆中分配大小为size字节的内存块
函数返回: 已分配的内存指针
参数说明: size-要分配的字节数
所属文件: <alloc.h>
#include <stdio.h>
#include <alloc.h>
#include <string.h>
#include <dos.h>
int main()
{
char far *fptr;
char *str="Hello";
fptr=farmalloc(10);
movedata(FP_SEG(str),FP_OFF(str),FP_SEG(fptr),FP_OFF(fptr),strlen(str));
printf("Far string is: %Fs",fptr);
farfree(fptr);
return 0;
}
@函数名称: farrealloc
函数原型: void far *farrealloc(void far *ptr,unsigned long newsize)
函数功能: 从远堆中重新分配大小为newsize字节的内存块
函数返回: 已分配的内存指针
参数说明: ptr 已分配的内存指针,newsize 要分配的字节数
所属文件: <alloc.h>
#include <stdio.h>
#include <alloc.h>
int main()
{
char far *fptr;
fptr=farmalloc(10);
printf("First address:%Fp",fptr);
fptr=farrealloc(fptr,20);
printf("New address:%Fp",fptr);
farfree(fptr);
return 0;
}
@函数名称: freemem
函数原型: int freemem(unsigned seg)
函数功能: 释放由allocmem()分配的内存块
函数返回: 0-操作成功,-1 操作失败
参数说明: seg 段地址
所属文件: <alloc.h>
#include <dos.h>
#include <alloc.h>
#include <stdio.h>
int main()
{
unsigned int size, segp;
int stat;
size=64; /* (64*16)=1024 bytes */
stat=allocmem(size, &segp);
if (stat<0)
printf("Allocated memory at segment:%x",segp);
else
printf("Failed: maximum number of paragraphs available is %u",stat);
freemem(segp);
return 0;
}
@函数名称: sbrk
函数原型: void *sbrk(int incr)
函数功能: 为数据段增加内存
函数返回:
参数说明: incr-数据段增加的字节数据
所属文件: <alloc.h>
#include <stdio.h>
#include <alloc.h>
int main()
{
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;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -