home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Black Box 4
/
BlackBox.cdr
/
progc
/
c_all592.arj
/
TI705.ASC
< prev
next >
Wrap
Text File
|
1992-02-25
|
2KB
|
133 lines
PRODUCT : Borland C++ NUMBER : 705
VERSION : 2.0
OS : DOS
DATE : February 25, 1992 PAGE : 1/2
TITLE : Allocating More Than 64K of Memory in DOS
/************************************************************************
This program demonstrates the dynamic allocation of a memory
block larger than 64K bytes using farcalloc(). It should not be
compiled in the Tiny memory model. The program calls farcoreleft
prior to allocating the block of memory to determine how much
memory is available. Note that this method will not be accurate
if memory has been previously allocated and then released as the
released memory is handled differently. If you choose to run this
program from inside the integrated development environment you
must set the head size under OPTIONS/DEBUGGER to at least the
size of the two parameters passed to farcalloc() + 5 bytes. Also
note that farcalloc can be interchanged freely with farmalloc or
farrealloc in this example.
***********************************************************************/
#include <stdio.h>
#include <alloc.h>
#include <string.h>
#include <dos.h>
#include <conio.h>
int main(void)
{
int huge *fptr;
unsigned long val;
clrscr();
/* Check the amount of memory available if no blocks have been
freed */
printf("\nMemory available on the far heap: %lu\n",val =
farcoreleft());
/* allocate memory for the far pointer */
fptr = (int huge *) farcalloc( 66000L, sizeof(int));
/* display string (note the F modifier) */
printf("Address of allocated block is: %Fp", fptr);
PRODUCT : Borland C++ NUMBER : 705
VERSION : 2.0
OS : DOS
DATE : February 25, 1992 PAGE : 2/2
TITLE : Allocating More Than 64K of Memory in DOS
/* Check how much memory is left */
printf("\nMemory left on the far heap: %lu\n",val =
farcoreleft());
getch();
/* free the memory */
farfree((int far *) fptr);
return 0;
}