farrealloc() bug in Turbo C

Joseph H Allen jhallen at wpi.wpi.edu
Fri May 4 19:25:23 AEST 1990


In article <1990May4.003455.1602 at egsner.cirr.com> clifton at egsner.cirr.com (Clifton Bean) writes:
>In article <6377 at vax1.acs.udel.EDU> ray at vax1.acs.udel.EDU (Thomas Ray) writes:

>>     The function farrealloc() in Turbo C is described as ``Adjusts allocated
>>block in far heap....  Blocks larger than 64K can be allocated''.  The
>>problem is that it only works for blocks of up to 64K.  I called their

>>     So, does anyone have a piece of code that can do a farrealloc() in
>>Turbo C, or can anyone write and test such a function?  It would be nice

You might consider using the MS-DOS memory allocator:

#include <dos.h>

void far *falloc(unsigned long size)
{
void far *block=0;
if(0xfff00000&size) return 0;
_BX=size&15?size/16+1:size/16;
_AH=0x48;
geninterrupt(0x21);
__emit__(0x73,2,0x28,0xc0);	/* Clear AX if Carry is set */
*(1+(unsigned *)&block)=_AX;
return block;
}

void ffree(void far *block)
{
_ES=FP_SEG(block);
_AH=0x49;
geninterrupt(0x21);
}

void far *frealloc(void far *block,unsigned long size)
{
if(0xfff00000&size) return 0;
_ES=FP_SEG(block);
_BX=size&15?size/16+1:size/16;
_AH=0x4a;
geninterrupt(0x21);
__emit__(0x73,2,0x28,0xc0);	/* Clear AX if Carry is set */
*(1+(unsigned *)&block)=_AX;
return block;
}

Be forewarned, however:  These are not compatible with turbo C's farm functions.
Also, presumably MS-DOS is slower than turbo C, so only use these if you're
not allocating very often.  Also, these have only been tested in small & tiny
models.

-- 
jhallen at wpi.wpi.edu (130.215.24.1)



More information about the Comp.lang.c mailing list