Borland C++ reference

farmalloc

raw OCR

Allocates from far heap.

Defined in header <alloc.h>

Syntax

#include <alloc.h>
void far *farmalloc(unsigned long nhytes);

Portability

DOSUNIXWindowsANSI CC++ only
■■

Remarks

farmalloc allocates a block of memory nhytes bytes long from the far heap.

For allocating from the far heap, note that

□ all available RAM can be allocated. u blocks larger than 64K can be allocated. □ far pointers are used to access the allocated blocks.

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

A tiny model program cannot make use of farmalloc.

Return value

farmalloc 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>
iinclude <alloc.h>
iinclude <string.h>
iinclude <dos.h>

int main(void)
{
   char far *fptr, *str = "Hello";

   /* allocate memory for the far pointer */
   fptr = (char far *) farmalloc (10);

   /* copy "Hello" into allocated memory */
   /* movedata is used because we 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) */
   printf("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.