Borland C++ reference

farcalloc

raw OCR

Allocates memory from the far heap.

Defined in header <alloc.h>

Syntax

#include <alloc.h>
void far *farcalloc(unsigned long nunits, unsigned long unitsz);

Portability

DOSUNIXWindowsANSI CC++ only
■■

Remarks

farcalloc allocates memory from the far heap for an array containing nunits elements, each unitsz bytes long.

For allocating from the far heap, note that

Q all available RAM can be allocated. ■ blocks larger than 64K can be allocated. B far pointers (or huge pointers if blocks are larger than 64K) are used to access the allocated blocks.

In the compact, large, and huge memory models, farcalloc is similar, though not identical, to calloc. It takes unsigned long parameters, while calloc takes unsigned parameters.

A tiny model program cannot make use of farcalloc.

Return value

farcalloc returns a pointer to the newly allocated block, or null if not enough space exists for the new block.

See also

Example

include  <stdio.h>
#include <alloc.h>
#include <string.h>
#include <dos.h>

int main(void)

   char far *fptr, *str = "Hello";
   /* allocate memory for the far pointer  */
   fptr = (char far *) farcalloc(10, sizeof(char)

   /* copy "Hello" into allocated memory  */
/* Note: movedata is used because you  might be in a small data model, in which
   case a normal string copy  routine can not be used since it assumes the
   pointer size is near. */
movedata (FP_SEG(Str), FP_OFF(str),
         FP_SEG(fptr), FP_OFF(fptr) ,
         strlen(str)
         );
/* display string  (note the F modifier) */
printfC'Far string is: %Fs\n",  fptr) ;

/* free the memory */
farfree(fptr) ;
return 0;

Differences from modern implementations

Nothing recorded yet.

Modern references

These are search links, not yet checked by hand.