home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turbo Toolbox
/
Turbo_Toolbox.iso
/
dtx9203
/
borhot
/
heapsz.c
next >
Wrap
C/C++ Source or Header
|
1992-03-25
|
2KB
|
56 lines
/* ------------------------------------------------------ */
/* HEAPSZ.C */
/* Function to Find Total Far Heap Free Memory */
/* */
/* This function will determine how much memory is */
/* available on the far heap. */
/* */
/* Usage: To use this function you must put the statement */
/* */
/* extern long heapsize(void); */
/* */
/* within the scope of the calling function. */
/* */
/* (c) 1991 Borland International */
/* All rights reserved. */
/* ------------------------------------------------------ */
/* veröffentlicht in DOS toolbox 3'92 */
/* ------------------------------------------------------ */
#include <alloc.h> // for heapinfo, heapcheck(),
// heapwalk(), coreleft() and HEAPOK
#include <stdio.h> // for printf()
unsigned long heapsize(void) {
unsigned long i = 0; // Return variable
struct heapinfo hi; // Value returned from farheapwalk
hi.ptr = NULL; // Set the beginning of farheapwalk
if (heapcheck() <= 0) // Check for corrupted heap
return (-1L);
// Walk the heap and sum size of free blocks
while (heapwalk(&hi) == _HEAPOK)
if (hi.in_use == 0)
i += hi.size;
// Check for amount of free memory from the highest
// allocated to the end of DOS
i += coreleft();
return i;
}
/* ------------------------------------------------------ */
int main()
{
unsigned long theap;
theap = heapsize();
printf("Heap available = %lu.\n", theap);
return 0;
}
/* ------------------------------------------------------ */
/* Ende von HEAPSZ.C */