#ifndef _THEAPSUMINFO_H_
//----------------------------------------------------
// ENG. Structures and functions for heap testing.
// Tested in
//     Microsoft Visual Studio 2008 Ñ++ Express
//     Borland Turbo C++ Explorer 2005
//     Qt Creator 2.0.1 Windows (Mingw).
//----------------------------------------------------
#define _THEAPSUMINFO_H_
#include <stddef.h>



//----------------------------------------------------------
typedef struct _THeapSumInfo
//----------------------------------------------------------
{
    size_t BlocksTotal;
    size_t BlocksUsed;
    size_t BlocksFree;
    size_t MaxFree;
    size_t MaxUsed;
    size_t FreeSum;
    size_t UsedSum;
    size_t TotalSum;
} THeapSumInfo;



//----------------------------------------------------------
typedef struct _THeapSumInfoDifference
//----------------------------------------------------------
{
    ptrdiff_t BlocksTotal;
    ptrdiff_t BlocksUsed;
    ptrdiff_t BlocksFree;
    ptrdiff_t MaxFree;
    ptrdiff_t MaxUsed;
    ptrdiff_t FreeSum;
    ptrdiff_t UsedSum;
    ptrdiff_t TotalSum;
} THeapSumInfoDifference;



#ifdef __cplusplus
extern "C" {
#endif

//---------------------------------------------------------
int GetHeapSumInfo (THeapSumInfo* Dst);
/* ENG. Fills THeapSumInfo struct by _heapwalk. Returns
0, if corrupted block has been found (Dst contents is
undefined). Otherwise returns 1, and Dst is filled.
---------------------------------------------------------*/



//---------------------------------------------------------------
void GetHeapSumInfoDifference (THeapSumInfo* Info1,
     THeapSumInfo* Info2, THeapSumInfoDifference *InfoDiff);
// InfoDiff = Info2 - Info1
//---------------------------------------------------------------



//----------------------------------------------------------
typedef struct _THeapSumInfoFieldPresenceFlag
//----------------------------------------------------------
{
    unsigned int BlocksTotal: 1;
    unsigned int BlocksUsed: 1;
    unsigned int BlocksFree: 1;
    unsigned int MaxFree: 1;
    unsigned int MaxUsed: 1;
    unsigned int FreeSum: 1;
    unsigned int UsedSum: 1;
    unsigned int TotalSum: 1;

} THeapSumInfoFieldPresenceFlag;


//--------------------------------------------------------------
void THeapSumInfo_to_cstring (
     THeapSumInfo *Info,
     char* Dst, // destination C-string
     const char* StartStr, // starting text (may be 0)
     const char* FieldSeparatorStr, // if 0, then "\r\n" used
     const char* EndStr, // if 0, then "\r\n" used
     const THeapSumInfoFieldPresenceFlag *PresenceFlagPtr); // if 0, then all fields present

void THeapSumInfoDifference_to_cstring (
     THeapSumInfoDifference *Info,
     char* Dst, // destination C-string
     const char* StartStr, // starting text (may be 0)
     const char* FieldSeparatorStr, // if 0, "\r\n" used
     const char* EndStr, // if 0, "\r\n" used
     const THeapSumInfoFieldPresenceFlag *PresenceFlagPtr); // if 0, then all fields present

/* Example:

     THeapSumInfo_to_cstring (&Info1, Dst, "[Info1]",0,0,0);

Rssulting text has 143 bytes:

[Info1]
BlocksTotal = 50
BlocksUsed = 48
BlocksFree = 2
MaxFree = 1344
MaxUsed = 6144
FreeSum = 1424
UsedSum = 16841
TotalSum = 18265
--------------------------------------------------------------*/



//------------------------------------------------
void SaveHeapSumInfoAndDifference (
     THeapSumInfo *Info1, THeapSumInfo *Info2,
     THeapSumInfoDifference *InfoDiff,
     const char* FileName);
//------------------------------------------------

#ifdef __cplusplus
}
#endif



#endif // ~_THEAPSUMINFO_H_
