/[escript]/trunk/esysUtils/src/mem.h
ViewVC logotype

Contents of /trunk/esysUtils/src/mem.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3259 - (show annotations)
Mon Oct 11 01:48:14 2010 UTC (8 years, 10 months ago) by jfenwick
File MIME type: text/plain
File size: 4550 byte(s)
Merging dudley and scons updates from branches

1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2010 by University of Queensland
5 * Earth Systems Science Computational Center (ESSCC)
6 * http://www.uq.edu.au/esscc
7 *
8 * Primary Business: Queensland, Australia
9 * Licensed under the Open Software License version 3.0
10 * http://www.opensource.org/licenses/osl-3.0.php
11 *
12 *******************************************************/
13
14
15 #ifndef INC_ESYS_MEM
16 #define INC_ESYS_MEM
17
18 /**************************************************************/
19 /* Macros to deal with memory management */
20 /********************************************/
21
22
23 /**************************************************************/
24 /* memory allocation: */
25 /* Wise to not use PASO_MALLOC/FREE/REALLOC and */
26 /* PASO_THREAD... directly. These are only for tailoring */
27 /* the main macros that follow */
28 /**************************************************************/
29
30
31 /*#if defined(_WIN32) */ /* Use python for memory management on windows. */
32 /*
33 #include <python.h>
34
35 #define PASO_MALLOC PyMem_Malloc
36 #define PASO_FREE PyMem_Free
37 #define PASO_REALLOC PyMem_Realloc
38
39 #else
40 */
41 #include <stdlib.h>
42
43 #define PASO_MALLOC malloc
44 #define PASO_FREE free
45 #define PASO_REALLOC realloc
46
47 /*#endif */
48
49 /* FIXME: This is not satisfactory. */
50 /* _ECC, __INTEL_COMPILER, and other */
51 /* intel compiler pre-defines need to be handled */
52 /* (__ICL, __ICC come to mind) */
53 /* Also, _WIN32 may take this branch one day... */
54 /* SO KEEP ALL THREAD_MEMALLOC/FREEs CONFINED TO THE PASO LIBRARY. */
55
56 #if defined(__ECC) && defined(_OPENMP) /* ECC version of intel compiler with openmp. */
57 #include <omp.h>
58 #define PASO_THREAD_MALLOC kmp_malloc
59 #define PASO_THREAD_FREE kmp_free
60 #else
61 #define PASO_THREAD_MALLOC PASO_MALLOC
62 #define PASO_THREAD_FREE PASO_FREE
63 #endif
64
65
66 /* Prepare for the day that this becomes sharable. */
67 /* and we wish to do multi-file optimisations on windows */
68
69 #define PASO_DLL_API
70
71 #ifdef _WIN32
72 # ifndef PASO_STATIC_LIB
73 # undef PASO_DLL_API
74 # ifdef PASO_EXPORTS
75 # define PASO_DLL_API __declspec(dllexport)
76 # else
77 # define PASO_DLL_API __declspec(dllimport)
78 # endif
79 # endif
80 #endif
81
82
83 /******************The main macros ************************************/
84
85 #define MEMALLOC(_LENGTH_,_TYPE_) \
86 (_TYPE_*) PASO_MALLOC(((size_t)(_LENGTH_))*sizeof(_TYPE_))
87
88 /* do {} while(0) - an old trick for bracketing a macro that */
89 /* makes sure a semi-colon does no harm. */
90
91 #define MEMFREE(_PTR_) \
92 do \
93 { \
94 if ((void *)(_PTR_) != NULL ) { PASO_FREE(_PTR_); (_PTR_) = NULL; } \
95 } while(0)
96
97 #define MEMREALLOC(_RETP_,_POINTER_,_LENGTH_,_TYPE_) \
98 do \
99 { \
100 if( (_POINTER_)!=NULL ) \
101 { \
102 _RETP_ = (_TYPE_*)PASO_REALLOC((void*)(_POINTER_), \
103 ((size_t)(_LENGTH_))*sizeof(_TYPE_) ); \
104 } \
105 else \
106 { \
107 _RETP_ = (_TYPE_*)PASO_MALLOC( ((size_t)(_LENGTH_))*sizeof(_TYPE_) ); \
108 } \
109 } while(0)
110
111 #define TMPMEMALLOC MEMALLOC
112 #define TMPMEMFREE MEMFREE
113 #define TMPMEMREALLOC MEMREALLOC
114
115 #define THREAD_MEMALLOC(_LENGTH_,_TYPE_) \
116 (_TYPE_*) PASO_THREAD_MALLOC/**/(((size_t)(_LENGTH_))*sizeof(_TYPE_))
117
118 #define THREAD_MEMFREE(_PTR_) \
119 do \
120 { \
121 if ((void *)(_PTR_) != NULL ) { PASO_THREAD_FREE(_PTR_); (_PTR_) = NULL; } \
122 } while(0)
123
124
125 #endif

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision
svn:mergeinfo /branches/lapack2681/paso/src/Common.h:2682-2741 /branches/restext/paso/src/Common.h:2610-2624 /branches/stage3.0/paso/src/Common.h:2569-2590 /release/3.0/paso/src/Common.h:2591-2601

  ViewVC Help
Powered by ViewVC 1.1.26