home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Troubleshooting Netware Systems
/
CSTRIAL0196.BIN
/
attach
/
msj
/
v10n10
/
oleq1195.exe
/
HEAPDET.H
< prev
next >
Wrap
C/C++ Source or Header
|
1995-10-01
|
2KB
|
81 lines
//////////////////////////////////////////////////////
//
// HeapDet.h - Copyright 1995, Don Box
//
// Simple IMallocSpy to track allocation byte count
//
#ifndef _HEAPDET_H
#define _HEAPDET_H
class CoHeapDetective : public IMallocSpy
{
public:
// this exception will be thrown if a bad ptr is detected
class XCorruptedHeap {};
CoHeapDetective(HANDLE hTrace = 0);
virtual ~CoHeapDetective();
DWORD GetBytesAlloced() const;
private:
// paramters to cache between pre/post phases
long m_cbLastAlloc;
void *m_pvLastRealloc;
// total heap usage
DWORD m_dwBytesAlloced;
// output device for tracing
HANDLE m_hTraceOutput;
// helper function to send simple trace message to debug window
void Trace(DWORD cb, LPCTSTR szAction, BOOL bSuccess);
// simple alloc header to track allocation size
struct ArenaHeader
{
enum { SIGNATURE = 0x1BADABBAL };
DWORD m_dwAllocSize; // the user's idea of size
DWORD m_dwSignature; // always 0x1BADABBA when good
};
// helper function to write a valid arena header at ptr
void SetArenaHeader(void *ptr, DWORD dwAllocSize);
// helper function to verify and return the prepended
// header (or null if failure)
ArenaHeader *GetHeader(void *ptr);
// IUnknown methods
STDMETHODIMP QueryInterface(REFIID riid, void**ppv);
STDMETHODIMP_(ULONG) AddRef();
STDMETHODIMP_(ULONG) Release();
// IMallocSpy methods
STDMETHODIMP_(ULONG) PreAlloc(ULONG cbRequest);
STDMETHODIMP_(void*) PostAlloc(void *pActual);
STDMETHODIMP_(void*) PreFree(void *pRequest, BOOL fSpyed);
STDMETHODIMP_(void) PostFree(BOOL fSpyed);
STDMETHODIMP_(ULONG) PreRealloc(void *pRequest, ULONG cbRequest,
void **ppNewRequest, BOOL fSpyed);
STDMETHODIMP_(void*) PostRealloc(void *pActual, BOOL fSpyed);
STDMETHODIMP_(void*) PreGetSize(void *pRequest, BOOL fSpyed);
STDMETHODIMP_(ULONG) PostGetSize(ULONG cbActual, BOOL fSpyed);
STDMETHODIMP_(void*) PreDidAlloc(void *pRequest, BOOL fSpyed);
STDMETHODIMP_(int) PostDidAlloc(void *pRequest, BOOL fSpyed, int fActual);
STDMETHODIMP_(void) PreHeapMinimize(void);
STDMETHODIMP_(void) PostHeapMinimize(void);
};
#endif