/* ##H_FILE#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
FILE :          PrivMmg.h
 
DESCRIPTION :   This a private header file in witch there are all the traget(define) that 
				you can change as you like inside of the library.                         
				Without any problem for the outsidethis file contain all functions and 
				macros used to allocate memory 
	
 
VERSION :       5.1.0/Pierrick Crepy/Creation
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/*#define D_CheckSystemForBlockWithoutFree*/
 
#ifdef U64
#undef __DEBUG_MALLOC_MODE__
/*#undef D_CheckSystemForBlockWithoutFree /*not now  */
#endif
 
#ifdef __DEBUG_MALLOC_MODE__
#define __ADD_PLACE_FOR_DEBUG_INFORMATION__
#endif /*__DEBUG_MALLOC_MODE__*/
 
/* ##CONSTANTE#--------------------------------------------------------------------------
                          Constantes declaration
---------------------------------------------------------------------------------------*/
/* multi thread management*/
#define C_ucMmgInvalidGroup	(0xFF)
 
#ifdef __DEBUG_MALLOC_MODE__
#define C_ucMallocHeaderSize (2) /*unitAlloc : size + DebugKey*/
#define C_ucMallocFooterSize (1) /*unitAlloc : DebugKey*/
 
#define C_ucOptimizedMallocHeaderSize (1) /*unitAlloc : size */
#define C_ucOptimizedMallocFooterSize (0) /*Nothing*/
#else
#define C_ucMallocHeaderSize (1) /*unitAlloc : size */
#define C_ucMallocFooterSize (0) /*Nothing*/
#endif /*__DEBUG_MALLOC_MODE__*/
#define C_ucFreeHeaderSize (2) /*unitAlloc : Size + Next*/
 
#define C_uaCleanKey						(0XAAAAAAAA)
 
#define C_uaCleanKeyForBlockWithoutFree		(0XAA)
 
#ifdef __DEBUG_MALLOC_MODE__
#define C_ucDebugInformationLoss (C_ucMallocHeaderSize - C_ucOptimizedMallocHeaderSize + C_ucMallocFooterSize - C_ucOptimizedMallocFooterSize)
 
/* the check keys around malloc*/
#define C_uaBeginKey						(0XB123456B) /* B for Begin*/
#define C_uaEndKey							(0XE123456E) /* E for End*/
#endif /*__DEBUG_MALLOC_MODE__*/
 
/* For the block without Free.*/
#define C_FirstFreeValueForBlockWithoutFree ((char *)0XFFFFFFFF)
#define C_TypeOfOverflowCheckKeyForBlockWithoutFree unsigned long
#define C_ulOverflowCheckKey				(0XE123456E) /* E for End*/
 
#ifdef __DEBUG_MALLOC_MODE__
/* for debug and statistic*/
#define C_ucNbPrintedColumn (150) /* number of column that we can display or for the log file*/
#define C_ucNbColumnForHisto (79)
#endif /*__DEBUG_MALLOC_MODE__*/
 
#ifdef __DEBUG_MALLOC_MODE__
/* for debug and statistic*/
#define C_szMmgLogFileName "Memory.log"/* name of the file used to print debug & statistic information*/
#define C_ucNbMaxFile 255 /* Number maximum of the file using any allocation functions.*/
#endif /*__DEBUG_MALLOC_MODE__*/
 
/* ##TYPEDEF#----------------------------------------------------------------------------
                          Types definition
---------------------------------------------------------------------------------------*/
/* ##-#################################################### */
/*        tdstInformationHeaderOfBolckWithoutFree          */
/* ####################################################### */
typedef struct tdstInformationHeaderOfBolckWithoutFree_{
	unsigned char ucBoundededHeaderSize;/* size of this header with alignement*/
	unsigned char ucAlignment;
	unsigned char ucMode;
}tdstInformationHeaderOfBolckWithoutFree;
 
/* ##-########################### */
/*        tdstMallocInfo          */
/* ############################## */
#ifdef __DEBUG_MALLOC_MODE__
typedef struct tdstMallocInfo_{
        char * p_cBeginMalloc;
        char * p_cEndMalloc;
} tdstMallocInfo;
#else /*__DEBUG_MALLOC_MODE__*/
typedef void tdstMallocInfo;
#endif /*__DEBUG_MALLOC_MODE__*/
 
/* ##-########################### */
/*        tdstBlockInfoPriv       */
/* ############################## */
typedef struct tdstBlockInfoPriv_{
        char * p_cBeginBlock;
        char * p_cEndBlock;
        char * p_cFirstFree;
        char * p_cMaxMem; 
#ifdef __DEBUG_MALLOC_MODE__
        unsigned long ulCountMallocBeforeMaxMem;/* the number of allocation before MaxMen (including the allocation who generated this MaxMem address)*/
        unsigned long ulCountFreeBeforeMaxMem;
        tdstMallocInfo  *d_stMallocInfo; 
		unsigned long ulMaxNbStaticMalloc; /*Nb of maximum allocations*/
        unsigned long ulNbMalloc; /* number of malloc used now*/
        unsigned long ulNbTotalMalloc; /* cumul*/
        unsigned short uwNbFree; /* number of free used now*/
        unsigned short ulNbTotalFree; /* cumul*/
        unsigned short ulNbTotalRealloc; /* cumul*/
#endif /*__DEBUG_MALLOC_MODE__*/
}tdstBlockInfoPriv;
 
 
/* ##-########################### */
/*        tdstDynInfo             */
/* ############################## */
#if defined (__DYNAMIC_MALLOC_ALLOWED__) && defined (__DEBUG_MALLOC_MODE__)
typedef struct tdstDynInfo_{
        tdstMallocInfo  *d_stDynamicMallocInfo;
		unsigned long ulMaxNbDynamicMalloc;
        unsigned long ulNbDynamicMalloc;/* Actual number*/
        unsigned short ulNbTotalDynamicMalloc;
        unsigned short ulNbTotalDynamicFree;
        unsigned short ulNbTotalDynamicRealloc;
}tdstDynInfo;
#else 
typedef void tdstDynInfo; 
#endif /*defined (__DYNAMIC_MALLOC_ALLOWED__) && defined (__DEBUG_MALLOC_MODE__)*/
 
 
/*//////////*/
/* Macros //*/
/*//////////*/
 
#ifdef __DEBUG_MALLOC_MODE__
 
/* ##M#===================================================================================
NAME :          Mmg_M_InitDynInfo
DESCRIPTION :   init a structure info for dynamic allocation
INPUT :         dynamic info structure
=========================================================================================
CREATION : 06-11-97/Crepy Pierrick
=======================================================================================*/
#define Mmg_M_InitDynInfo(p_stMyDynInfo)\
/*              -------------------  only used in Mmg_M_InitMmg when __DYNAMIC_MALLOC_ALLOWED__ is defined*/\
{\
        (p_stMyDynInfo)->ulNbDynamicMalloc = 0;/* Actual number */\
        (p_stMyDynInfo)->ulNbTotalDynamicMalloc =0;\
        (p_stMyDynInfo)->ulNbTotalDynamicFree =0;\
        (p_stMyDynInfo)->ulNbTotalDynamicRealloc =0;\
}
#else /*__DEBUG_MALLOC_MODE__*/
#define Mmg_M_InitDynInfo(p_stMyDynInfo) /*Nothing to do*/
#endif /*__DEBUG_MALLOC_MODE__*/
 
/* ##M#===================================================================================
NAME :          Mmg_M_UpdateLastErrorWithoutMessage
DESCRIPTION :   Raise an error without window message
INPUT :         error Id
				text message
=========================================================================================
CREATION : 06-11-97/Crepy Pierrick
=======================================================================================*/
#define Mmg_M_UpdateLastErrorWithoutMessage(uwMyErr, szPersonalTxt) Erm_M_UpdateLastError (Mmg, C_ucErmDefaultChannel, uwMyErr, C_lErmNoDebugData, C_ucErmNoOpenInfoWindow, C_ucNeverStopForDebug, szPersonalTxt);
