/* *%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% * Mem.c * Managment of memory. * CPA_Ed_1 team * *%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */ /* *================================================================================================= * Includes. *================================================================================================= */ /* conditional compilation */ #ifdef LDT_USE_MMG #include "StdInc.h" #if !defined(U64) #define __DeclareGlobalVariableMmgLDT_h__ #define __DeclareGlobalVariableErrLDT_h__ #include "Mem.h" #include "ErrLDT.h" /* ERM */ #include "MmgLDT.h" /* MMG */ #undef __DeclareGlobalVariableMmgLDT_h__ #undef __DeclareGlobalVariableErrLDT_h__ #endif /* U64 */ /* *------------------------------------------------------------------------------------------------- * malloc *------------------------------------------------------------------------------------------------- */ void* LDT_malloc_Mmg(size_t _size) { void* _Pointer; Mmg_M_SetModeAlloc4Ch(LDT, E_ucDynamic, C_ucMmgDefaultChannel); _Pointer = Mmg_fn_p_vAlloc4Ch(_size, C_ucMmgDefaultChannel); if(Erm_M_uwCheckError(Mmg, C_ucErmDefaultChannel)) Erm_M_ClearLastError(C_ucErmDefaultChannel); if(_Pointer == NULL){}; return _Pointer; } /* *------------------------------------------------------------------------------------------------- * realloc *------------------------------------------------------------------------------------------------- */ void *LDT_realloc_Mmg(void * _PointerSrc, size_t _Size) { Mmg_M_SetModeAlloc4Ch(LDT, E_ucDynamic, C_ucMmgDefaultChannel); _PointerSrc = Mmg_fn_p_vRealloc4Ch(_PointerSrc, _Size , C_ucMmgDefaultChannel); if(Erm_M_uwCheckError(Mmg, C_ucErmDefaultChannel)) Erm_M_ClearLastError(C_ucErmDefaultChannel); if(_PointerSrc == NULL) { }; return _PointerSrc; } /* *------------------------------------------------------------------------------------------------- * free *------------------------------------------------------------------------------------------------- */ void LDT_free_Mmg(void *_Pointer) { if(_Pointer) { Mmg_M_SetModeAlloc4Ch(LDT, E_ucDynamic, C_ucMmgDefaultChannel); if(Erm_M_uwCheckError(Mmg, C_ucErmDefaultChannel)) Erm_M_ClearLastError(C_ucErmDefaultChannel); Mmg_fn_vFree4Ch(_Pointer, C_ucMmgDefaultChannel); _Pointer = NULL; } } /* *------------------------------------------------------------------------------------------------- * Init of memory managment. *------------------------------------------------------------------------------------------------- */ void LDT_fn_v_Mem_InitModule(void) { static char s_cFirstInit = 1; /* Must init only one time error module (in case of multiple script init/close) */ if(s_cFirstInit == 1) { Erm_M_InitErrMsg(LDT); s_cFirstInit = 0; } Mmg_M_InitMmg(LDT); } /* *------------------------------------------------------------------------------------------------- * Close. *------------------------------------------------------------------------------------------------- */ void LDT_fn_v_Mem_CloseModule(void) { Mmg_fn_v_StopMmg(Erm_M_ucGiveModuleId(LDT)); } /* *------------------------------------------------------------------------------------------------- * Init of memory managment. * Use of MMG and ERM modules. * _p_ulMemorySize : Address of unsigned long size for blocs. Size if 0 for a dynamic malloc. *------------------------------------------------------------------------------------------------- */ void LDT_fn_v_Mem_InitWithMemLevel(unsigned long *_p_ulMemorySize) { unsigned char ucIndex; for(ucIndex = 0; ucIndex < E_ucLDTMaxBlocksNb; ucIndex++) { Mmg_M_InitBlockV5_1_0(LDT, ucIndex, *_p_ulMemorySize,200000); _p_ulMemorySize++; } } #endif /* LDT_USE_MMG */