home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Monster Media 1994 #1
/
monster.zip
/
monster
/
PROG_GEN
/
FACETV.ZIP
/
HEAPVIEW.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1994-01-04
|
2KB
|
111 lines
/************************************************************************
**
** @(#)heapview.cpp 04/01/93 Chris Ahlstrom
**
** --------------------------
** 73340.26!compuserve.com
** --------------------------
**
** The THeapView from Borland's GADGETS modules. I stole it! And
** added the ability to turn it on and off at run-time.
**
** Some code Copyright (c) 1991 by Borland International
**
** Gadgets for the Turbo Vision Demo. Includes the heap view which
** displays the current heap space at the right end of the status line.
**
*************************************************************************/
#define HEAPVIEW_cpp
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <strstrea.h>
#include <iomanip.h>
#include <alloc.h>
#include "heapview.h"
THeapView::THeapView
(
TRect& r
) :
TView( r )
{
oldMem = 0;
newMem = heapSize();
turnHeapOff = 0;
}
void
THeapView::draw ()
{
TDrawBuffer buf;
char c = getColor(2);
buf.moveChar(0, ' ', c, size.x);
buf.moveStr(0, heapStr, c);
writeLine(0, 0, size.x, 1, buf);
}
void
THeapView::update ()
{
if ((newMem = heapSize()) != oldMem)
{
oldMem = newMem;
drawView();
}
}
void
THeapView::clearLine ()
{
ostrstream totalStr(heapStr, sizeof heapStr);
totalStr << " " << ends;
drawView(); // draw the blank string
turnHeapOff = 1; // tell idle() what to do
}
long
THeapView::heapSize ()
{
long total = farcoreleft();
struct farheapinfo heap;
ostrstream totalStr(heapStr, sizeof heapStr);
switch (farheapcheck())
{
case _HEAPEMPTY:
strcpy(heapStr, " No heap");
total = -1;
break;
case _HEAPCORRUPT:
strcpy(heapStr, "Heap corrupt");
total = -2;
break;
case _HEAPOK:
heap.ptr = NULL;
while(farheapwalk(&heap) != _HEAPEND)
{
if (!heap.in_use)
total += heap.size;
}
totalStr << setw(12) << total << ends;
break;
}
return(total);
}