TC 2.0 里边的farcoreleft( )函数是用来测试“远堆”空闲字节数的,也就是返回可供程序动态申请的内存大小。因此,程序员如果自己能用c语言编写该函数的代码是有意义的。下面发布的就是这样一个东东:
unsigned long farcoreleft( void )
{ /*返回far heap中空闲字节数*/
extern unsigned short _heaptop[2];
extern unsigned short _brklvl[2];
return 16L*(_heaptop[1]-_brklvl[1])+(_heaptop[0]-_brklvl[0]);
}
【注意】全局变量 _heaptop、_brklvl是在 c0s.obj(或c0h.obj等)中定义的。令人遗憾的是这个代码恐怕只能在Turboc中使用,因为其他的c语言编译器似乎“不承认”这样名字的全局变量哦!如果把上面的代码写成内嵌asm格式,则为
unsigned long farcoreleft( void )
{ /*返回far heap中空闲字节数*/
extern unsigned short _heaptop[2];
extern unsigned short _brklvl[2];
asm push Ds /*为兼容 -mh 即huge模式而设*/
asm mov ax,SEG _heaptop /*为兼容 -mh 即huge模式而设*/
asm mov Ds,ax /*为兼容 -mh 即huge模式而设*/
asm mov ax,_heaptop[2] /*其实是_heaptop[]的1号元素*/
asm sub ax,_brklvl[2] /*情况同上*/
asm mov dx,16
asm mul dx
asm add ax,_heaptop[0]
asm adc dx,0
asm sub ax,_brklvl[0]
asm sbb dx,0
asm pop Ds /*为兼容 -mh 即huge模式而设*/
}
unsigned long farcoreleft( void )
{ /*返回far heap中空闲字节数*/
extern unsigned short _heaptop[2];
extern unsigned short _brklvl[2];
return 16L*(_heaptop[1]-_brklvl[1])+(_heaptop[0]-_brklvl[0]);
}
【注意】全局变量 _heaptop、_brklvl是在 c0s.obj(或c0h.obj等)中定义的。令人遗憾的是这个代码恐怕只能在Turboc中使用,因为其他的c语言编译器似乎“不承认”这样名字的全局变量哦!如果把上面的代码写成内嵌asm格式,则为
unsigned long farcoreleft( void )
{ /*返回far heap中空闲字节数*/
extern unsigned short _heaptop[2];
extern unsigned short _brklvl[2];
asm push Ds /*为兼容 -mh 即huge模式而设*/
asm mov ax,SEG _heaptop /*为兼容 -mh 即huge模式而设*/
asm mov Ds,ax /*为兼容 -mh 即huge模式而设*/
asm mov ax,_heaptop[2] /*其实是_heaptop[]的1号元素*/
asm sub ax,_brklvl[2] /*情况同上*/
asm mov dx,16
asm mul dx
asm add ax,_heaptop[0]
asm adc dx,0
asm sub ax,_brklvl[0]
asm sbb dx,0
asm pop Ds /*为兼容 -mh 即huge模式而设*/
}