> farmalloc() in c ~ Online tutorial

farmalloc() in c



 farmalloc()
 Allocates from far heap

 Declaration:

 void far *farmalloc(unsigned long nbytes);

 Remarks:

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



 Return Value:

  On success, farmalloc returns a pointer
    to the newly allocated block
   On failure (not enough space exists for
    the new block), farmalloc returns null




 Example:

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

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

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

    /* copy "Hello" into allocated memory */
    /*
       Note: 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) + 1);

    /* display string (note the F modifier)
*/
    printf("Far string is: %Fs\n", fptr);

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

    return 0;
 }

Please Give Us Your 1 Minute In Sharing This Post!
Please Give Us Your 1 Minute In Sharing This Post!
SOCIALIZE IT →
FOLLOW US →
SHARE IT →
Powered By: BloggerYard.Com

0 comments: