heap only needed under windows
This commit is contained in:
parent
83e19c5174
commit
bea58219e7
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
165
src/misc/alloc.c
165
src/misc/alloc.c
|
|
@ -6,25 +6,22 @@ $Id$
|
|||
/*
|
||||
* Memory alloction functions
|
||||
*/
|
||||
#include <config.h>
|
||||
#include "ngspice.h"
|
||||
|
||||
#ifndef HAVE_LIBGC
|
||||
#include <ngspice.h>
|
||||
#include <stdio.h>
|
||||
#include <memory.h>
|
||||
|
||||
/*saj For Tcl module locking*/
|
||||
#ifdef TCL_MODULE
|
||||
#include <tcl.h>
|
||||
//#include <tclDecls.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef HAS_WINDOWS
|
||||
#if defined(_MSC_VER) || defined(__MINGW32__)
|
||||
#undef BOOLEAN
|
||||
#include <windows.h>
|
||||
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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue