From bea58219e7733ca74abd1b7e61aabef51e8ddb1d Mon Sep 17 00:00:00 2001 From: dwarning Date: Fri, 9 Jan 2009 20:19:57 +0000 Subject: [PATCH] heap only needed under windows --- ChangeLog | 3 + src/frontend/outitf.c | 2 +- src/misc/alloc.c | 165 +++++++++++++++++++++--------------------- 3 files changed, 85 insertions(+), 85 deletions(-) diff --git a/ChangeLog b/ChangeLog index 62ad88c3f..ffe61c9d2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2009-01-09 Dietmar Warning + * src/misc/alloc.c, src/frontend/outitf.c: heap only needed under windows for zoom + 2009-01-05 Dietmar Warning * src/math/misc/isinf.c, isnan.c, src/include/missing_math.h: small polish for HAVE_DECL_XXX macros, more elaborate isinf function diff --git a/src/frontend/outitf.c b/src/frontend/outitf.c index f71eb6ca1..53be1bdec 100644 --- a/src/frontend/outitf.c +++ b/src/frontend/outitf.c @@ -66,7 +66,7 @@ static void freeRun(runDesc *run); /* plot output data shall go into extra heap to prevent massive memory fragmentation of standard process heap */ -#if defined(_MSC_VER) || defined(__MINGW32__) +#if defined HAS_WINDOWS && (defined(_MSC_VER) || defined(__MINGW32__)) #define newrealloc hrealloc #else #define newrealloc trealloc diff --git a/src/misc/alloc.c b/src/misc/alloc.c index 719e673d5..d712464c0 100644 --- a/src/misc/alloc.c +++ b/src/misc/alloc.c @@ -6,25 +6,22 @@ $Id$ /* * Memory alloction functions */ -#include +#include "ngspice.h" #ifndef HAVE_LIBGC -#include -#include -#include /*saj For Tcl module locking*/ #ifdef TCL_MODULE #include -//#include #endif - +#ifdef HAS_WINDOWS #if defined(_MSC_VER) || defined(__MINGW32__) #undef BOOLEAN #include extern HANDLE outheap; #endif +#endif /* Malloc num bytes and initialize to zero. Fatal error if the space can't * be tmalloc'd. Return NULL for a request for 0 bytes. @@ -59,84 +56,6 @@ tmalloc(size_t num) return(s); } -void * -trealloc(void *ptr, size_t num) -{ - void *s; -/*saj*/ -#ifdef TCL_MODULE - Tcl_Mutex *alloc; - alloc = Tcl_GetAllocMutex(); -#endif - if (!num) { - if (ptr) - free(ptr); - return NULL; - } - - if (!ptr) - s = tmalloc(num); - else { -/*saj*/ -#ifdef TCL_MODULE - Tcl_MutexLock(alloc); -#endif - s = realloc(ptr, num); -/*saj*/ -#ifdef TCL_MODULE - Tcl_MutexUnlock(alloc); -#endif - } - if (!s) { - fprintf(stderr,"realloc: Internal Error: can't allocate %ld bytes.\n", (long)num); - exit(EXIT_BAD); - } - return(s); -} - -/* realloc using the output heap. - Function is used in outitf.c to prevent heap fragmentation - An additional heap outheap is used to store the plot output data. -*/ -#if defined(_MSC_VER) || defined(__MINGW32__) -void * -hrealloc(void *ptr, size_t num) -{ - void *s; -/*saj*/ -#ifdef TCL_MODULE - Tcl_Mutex *alloc; - alloc = Tcl_GetAllocMutex(); -#endif - if (!num) { - if (ptr) - free(ptr); - return NULL; - } - - if (!ptr) - s = HeapAlloc(outheap, HEAP_ZERO_MEMORY, num); - else { -/*saj*/ -#ifdef TCL_MODULE - Tcl_MutexLock(alloc); -#endif - s = HeapReAlloc(outheap, HEAP_ZERO_MEMORY, ptr, num); -/*saj*/ -#ifdef TCL_MODULE - Tcl_MutexUnlock(alloc); -#endif - } - if (!s) { - fprintf(stderr,"HeapReAlloc: Internal Error: can't allocate %ld bytes.\n", (long)num); - exit(EXIT_BAD); - } - return(s); -} -#endif - - - /* Original Berkeley Implementation */ /* void * @@ -185,6 +104,84 @@ trealloc(void *str, size_t num) */ +void * +trealloc(void *ptr, size_t num) +{ + void *s; +/*saj*/ +#ifdef TCL_MODULE + Tcl_Mutex *alloc; + alloc = Tcl_GetAllocMutex(); +#endif + if (!num) { + if (ptr) + free(ptr); + return NULL; + } + + if (!ptr) + s = tmalloc(num); + else { +/*saj*/ +#ifdef TCL_MODULE + Tcl_MutexLock(alloc); +#endif + s = realloc(ptr, num); +/*saj*/ +#ifdef TCL_MODULE + Tcl_MutexUnlock(alloc); +#endif + } + if (!s) { + fprintf(stderr,"realloc: Internal Error: can't allocate %ld bytes.\n", (long)num); + exit(EXIT_BAD); + } + return(s); +} + +/* realloc using the output heap. + Function is used in outitf.c to prevent heap fragmentation + An additional heap outheap is used to store the plot output data. +*/ +#ifdef HAS_WINDOWS +#if defined(_MSC_VER) || defined(__MINGW32__) +void * +hrealloc(void *ptr, size_t num) +{ + void *s; +/*saj*/ +#ifdef TCL_MODULE + Tcl_Mutex *alloc; + alloc = Tcl_GetAllocMutex(); +#endif + if (!num) { + if (ptr) + free(ptr); + return NULL; + } + + if (!ptr) + s = HeapAlloc(outheap, HEAP_ZERO_MEMORY, num); + else { +/*saj*/ +#ifdef TCL_MODULE + Tcl_MutexLock(alloc); +#endif + s = HeapReAlloc(outheap, HEAP_ZERO_MEMORY, ptr, num); +/*saj*/ +#ifdef TCL_MODULE + Tcl_MutexUnlock(alloc); +#endif + } + if (!s) { + fprintf(stderr,"HeapReAlloc: Internal Error: can't allocate %ld bytes.\n", (long)num); + exit(EXIT_BAD); + } + return(s); +} +#endif +#endif + void txfree(void *ptr)