2 * NOTICE and LICENSE for Tecplot Input/Output Library (TecIO) - OpenFOAM
4 * Copyright (C) 1988-2009 Tecplot, Inc. All rights reserved worldwide.
6 * Tecplot hereby grants OpenCFD limited authority to distribute without
7 * alteration the source code to the Tecplot Input/Output library, known
8 * as TecIO, as part of its distribution of OpenFOAM and the
9 * OpenFOAM_to_Tecplot converter. Users of this converter are also hereby
10 * granted access to the TecIO source code, and may redistribute it for the
11 * purpose of maintaining the converter. However, no authority is granted
12 * to alter the TecIO source code in any form or manner.
14 * This limited grant of distribution does not supersede Tecplot, Inc.'s
15 * copyright in TecIO. Contact Tecplot, Inc. for further information.
18 * 3535 Factoria Blvd, Ste. 550
19 * Bellevue, WA 98006, USA
20 * Phone: +1 425 653 1200
21 * http://www.tecplot.com/
27 #define TECPLOTENGINEMODULE
30 ******************************************************************
31 ******************************************************************
33 ****** (C) 1988-2008 Tecplot, Inc. *******
35 ******************************************************************
36 ******************************************************************
43 #if defined TECPLOTKERNEL
44 /* CORE SOURCE CODE REMOVED */
47 #if defined TRACK_MEMORY_USAGE
48 static size_t memInUse
= 0;
49 static size_t memTotalHighMark
= 0;
50 static size_t memCurrentHighMark
= 0;
51 static size_t memSavedHighMark
= 0;
54 void initMemoryUsageTracking(void)
56 REQUIRE(!Thread_ThreadingIsInitialized());
57 Thread_InitMutex(&memMutex
);
60 void cleanUpMemoryUsageTracking(void)
62 REQUIRE(!Thread_ThreadingIsInitialized());
63 Thread_FreeMutex(&memMutex
);
66 void trackMemoryClearHighMark(void)
68 memCurrentHighMark
= memInUse
;
71 void trackMemorySaveHighMark(void)
73 memSavedHighMark
= memCurrentHighMark
;
76 void trackMemoryAlloc(size_t size
)
78 REQUIRE(memInUse
>= 0);
80 if (Thread_ThreadingIsInitialized())
81 Thread_LockMutex(memMutex
);
84 if (memInUse
> memTotalHighMark
)
85 memTotalHighMark
= memInUse
;
86 if (memInUse
> memCurrentHighMark
)
87 memCurrentHighMark
= memInUse
;
89 if (Thread_ThreadingIsInitialized())
90 Thread_UnlockMutex(memMutex
);
93 void trackMemoryFree(size_t size
)
95 if (Thread_ThreadingIsInitialized())
96 Thread_LockMutex(memMutex
);
100 if (Thread_ThreadingIsInitialized())
101 Thread_UnlockMutex(memMutex
);
103 ENSURE(memInUse
>= 0);
106 void getMemoryUsage(size_t* memoryInUse
,
107 size_t* memoryCurrentHighMark
,
108 size_t* memorySavedHighMark
,
109 size_t* memoryTotalHighMark
)
111 REQUIRE(VALID_REF_OR_NULL(memoryInUse
));
112 REQUIRE(VALID_REF_OR_NULL(memoryCurrentHighMark
));
113 REQUIRE(VALID_REF_OR_NULL(memorySavedHighMark
));
114 REQUIRE(VALID_REF_OR_NULL(memoryTotalHighMark
));
115 if (memoryInUse
!= NULL
)
116 *memoryInUse
= memInUse
;
117 if (memoryCurrentHighMark
!= NULL
)
118 *memoryCurrentHighMark
= memCurrentHighMark
;
119 if (memorySavedHighMark
!= NULL
)
120 *memorySavedHighMark
= memSavedHighMark
;
121 if (memoryTotalHighMark
!= NULL
)
122 *memoryTotalHighMark
= memTotalHighMark
;
126 #if defined MSWIN && defined ALLOC_HEAP
130 #if defined MSWIN && defined ALLOC_HEAP
133 void *MSWinAlloc(DWORD nSize
)
137 pMem
= (long *)malloc(sizeof(long) + nSize
);
139 pMem
= (long *)HeapAlloc(GetProcessHeap(), NULL
, sizeof(long) + nSize
);
142 return (void *)&(pMem
[1]);
146 #if defined MSWIN && defined ALLOC_HEAP
149 void MSWinFree(void *pMem
)
151 REQUIRE(VALID_REF(pMem
));
154 long *pMemLong
= &(((long *)pMem
)[-1]);
155 if (pMemLong
[0] < HEAPMIN
)
156 free((void *)pMemLong
);
158 HeapFree(GetProcessHeap(), NULL
, (void *)pMemLong
);