Added option to trace memory allocation

svn-id: r23904
This commit is contained in:
Chris Apers 2006-09-17 09:46:06 +00:00
parent 24f55e47e1
commit 42dd017faf
2 changed files with 32 additions and 5 deletions

View File

@ -24,6 +24,10 @@
#include <stdlib.h>
#ifdef STDLIB_TRACE_MEMORY
UInt32 __stdlib_trace_memory = 0;
#endif
#define memNewChunkFlagAllowLarge 0x1000
SysAppInfoPtr SysGetAppInfo(SysAppInfoPtr *uiAppPP, SysAppInfoPtr *actionCodeAppPP) SYS_TRAP(sysTrapSysGetAppInfo);
@ -60,6 +64,9 @@ MemPtr __malloc(UInt32 size) {
newP = MemChunkNew(0, size, attr);
}
#ifdef STDLIB_TRACE_MEMORY
__stdlib_trace_memory += size;
#endif
return newP;
}
@ -72,18 +79,33 @@ MemPtr calloc(UInt32 nelem, UInt32 elsize) {
if (newP)
MemSet(newP,size,0);
#ifdef STDLIB_TRACE_MEMORY
__stdlib_trace_memory += size;
#endif
return newP;
}
Err free(MemPtr memP) {
if (memP)
if (memP) {
#ifdef STDLIB_TRACE_MEMORY
UInt32 sz = MemPtrSize(memP);
__stdlib_trace_memory -= sz;
#endif
return MemPtrFree(memP);
}
return memErrInvalidParam;
}
MemPtr realloc(MemPtr oldP, UInt32 size) {
MemPtr newP;
#ifdef STDLIB_TRACE_MEMORY
UInt32 sz = MemPtrSize(oldP);
__stdlib_trace_memory -= sz;
__stdlib_trace_memory += size;
#endif
if (oldP != NULL)
if (MemPtrResize(oldP, size) == 0)
return oldP;

View File

@ -36,12 +36,17 @@ extern "C" {
#endif
/* malloc stuff */
#if defined(COMPILE_ZODIAC)
# define malloc MemPtrNew
#elif defined(COMPILE_OS5) && defined(PALMOS_ARM)
#ifdef STDLIB_TRACE_MEMORY
# define malloc __malloc
extern UInt32 __stdlib_trace_memory;
#else
# define malloc MemGluePtrNew
# if defined(COMPILE_ZODIAC)
# define malloc MemPtrNew
# elif defined(COMPILE_OS5) && defined(PALMOS_ARM)
# define malloc __malloc
# else
# define malloc MemGluePtrNew
# endif
#endif
/* custom exit (true exit !) */