From 42dd017faf6a34ad7747c9d4ab4985576aa50546 Mon Sep 17 00:00:00 2001 From: Chris Apers Date: Sun, 17 Sep 2006 09:46:06 +0000 Subject: Added option to trace memory allocation svn-id: r23904 --- backends/platform/PalmOS/Src/missing/ext_stdlib.c | 24 ++++++++++++++++++++++- backends/platform/PalmOS/Src/missing/stdlib.h | 13 ++++++++---- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/backends/platform/PalmOS/Src/missing/ext_stdlib.c b/backends/platform/PalmOS/Src/missing/ext_stdlib.c index 8c8fbd50bd..701e3bca69 100644 --- a/backends/platform/PalmOS/Src/missing/ext_stdlib.c +++ b/backends/platform/PalmOS/Src/missing/ext_stdlib.c @@ -24,6 +24,10 @@ #include +#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; diff --git a/backends/platform/PalmOS/Src/missing/stdlib.h b/backends/platform/PalmOS/Src/missing/stdlib.h index 8b1c959c01..95e65b3232 100644 --- a/backends/platform/PalmOS/Src/missing/stdlib.h +++ b/backends/platform/PalmOS/Src/missing/stdlib.h @@ -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 !) */ -- cgit v1.2.3