Changeset 1441 for trunk/psLib/src/sysUtils/psMemory.h
- Timestamp:
- Aug 9, 2004, 1:40:55 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/sysUtils/psMemory.h (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/sysUtils/psMemory.h
r1440 r1441 1 1 #if !defined(PS_MEMORY_H) 2 # define PS_MEMORY_H2 #define PS_MEMORY_H 3 3 4 4 /** @file psMemory.h … … 15 15 * @ingroup MemoryManagement 16 16 * 17 * @version $Revision: 1.2 6$ $Name: not supported by cvs2svn $18 * @date $Date: 2004-08-09 23: 34:58$17 * @version $Revision: 1.27 $ $Name: not supported by cvs2svn $ 18 * @date $Date: 2004-08-09 23:40:55 $ 19 19 * 20 20 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii 21 21 */ 22 22 23 # include <stdio.h> // needed for FILE24 # include <stdbool.h>25 # include <pthread.h> // we need a mutex to make this stuff thread safe.23 #include <stdio.h> // needed for FILE 24 #include <stdbool.h> 25 #include <pthread.h> // we need a mutex to make this stuff thread safe. 26 26 27 27 /** @addtogroup MemoryManagement … … 122 122 * @see psFree 123 123 */ 124 # ifdef DOXYGEN124 #ifdef DOXYGEN 125 125 void *psAlloc(size_t size ///< Size required 126 126 ); 127 # else128 129 void *p_psAlloc(size_t size, ///< Size required130 const char *file, ///< File of call131 int lineno ///< Line number of call132 );127 #else 128 129 void *p_psAlloc(size_t size, ///< Size required 130 const char *file, ///< File of call 131 int lineno ///< Line number of call 132 ); 133 133 134 134 void p_psMemSetDeallocator(void *ptr, psFreeFcn freeFcn); … … 136 136 137 137 /// Memory allocation. psAlloc sends file and line number to p_psAlloc. 138 # define psAlloc(size) p_psAlloc(size, __FILE__, __LINE__)139 # endif138 #define psAlloc(size) p_psAlloc(size, __FILE__, __LINE__) 139 #endif 140 140 141 141 /** Memory re-allocation. This operates much like realloc(), but is guaranteed to return a non-NULL value. … … 144 144 * @see psAlloc, psFree 145 145 */ 146 # ifdef DOXYGEN146 #ifdef DOXYGEN 147 147 void *psRealloc(void *ptr ///< Pointer to re-allocate 148 148 size_t size, ///< Size required 149 149 ); 150 # else151 152 void *p_psRealloc(void *ptr, ///< Pointer to re-allocate153 size_t size, ///< Size required154 const char *file, ///< File of call155 int lineno ///< Line number of call156 );150 #else 151 152 void *p_psRealloc(void *ptr, ///< Pointer to re-allocate 153 size_t size, ///< Size required 154 const char *file, ///< File of call 155 int lineno ///< Line number of call 156 ); 157 157 158 158 /// Memory re-allocation. psRealloc sends file and line number to p_psRealloc. 159 # define psRealloc(ptr, size) p_psRealloc(ptr, size, __FILE__, __LINE__)160 161 # endif159 #define psRealloc(ptr, size) p_psRealloc(ptr, size, __FILE__, __LINE__) 160 161 #endif 162 162 163 163 /** Free memory. This operates much like free(). … … 165 165 * @see psAlloc, psRealloc 166 166 */ 167 # ifdef DOXYGEN167 #ifdef DOXYGEN 168 168 void psFree(void *ptr, ///< Pointer to free, if NULL, function returns immediately. 169 169 ); 170 # else171 172 void p_psFree(void *ptr, ///< Pointer to free173 const char *file, ///< File of call174 int lineno ///< Line number of call175 );170 #else 171 172 void p_psFree(void *ptr, ///< Pointer to free 173 const char *file, ///< File of call 174 int lineno ///< Line number of call 175 ); 176 176 177 177 /// Free memory. psFree sends file and line number to p_psFree. 178 # define psFree(size) p_psFree(size, __FILE__, __LINE__)179 180 # endif178 #define psFree(size) p_psFree(size, __FILE__, __LINE__) 179 180 #endif 181 181 182 182 /** Check for memory leaks. This scans for allocated memory buffers not freed with an ID not less than id0. … … 218 218 * @ingroup memRefCount 219 219 */ 220 # ifdef DOXYGEN220 #ifdef DOXYGEN 221 221 void *psMemIncrRefCounter(void *vptr ///< Pointer to increment refCounter, and return 222 222 ); 223 # else224 225 void *p_psMemIncrRefCounter(void *vptr, ///< Pointer to increment refCounter, and return226 const char *file, ///< File of call227 int lineno ///< Line number of call228 );229 230 # define psMemIncrRefCounter(vptr) p_psMemIncrRefCounter(vptr, __FILE__, __LINE__)231 # endif223 #else 224 225 void *p_psMemIncrRefCounter(void *vptr, ///< Pointer to increment refCounter, and return 226 const char *file, ///< File of call 227 int lineno ///< Line number of call 228 ); 229 230 #define psMemIncrRefCounter(vptr) p_psMemIncrRefCounter(vptr, __FILE__, __LINE__) 231 #endif 232 232 233 233 /** Decrement reference counter and return the pointer … … 235 235 * @ingroup memRefCount 236 236 */ 237 # ifdef DOXYGEN237 #ifdef DOXYGEN 238 238 void *psMemDecrRefCounter(void *vptr ///< Pointer to decrement refCounter, and return 239 239 ); 240 # else241 242 void *p_psMemDecrRefCounter(void *vptr, ///< Pointer to decrement refCounter, and return243 const char *file, ///< File of call244 int lineno ///< Line number of call245 );246 247 # define psMemDecrRefCounter(vptr) p_psMemDecrRefCounter(vptr, __FILE__, __LINE__)248 # endif240 #else 241 242 void *p_psMemDecrRefCounter(void *vptr, ///< Pointer to decrement refCounter, and return 243 const char *file, ///< File of call 244 int lineno ///< Line number of call 245 ); 246 247 #define psMemDecrRefCounter(vptr) p_psMemDecrRefCounter(vptr, __FILE__, __LINE__) 248 #endif 249 249 250 250 /** Set callback for problems … … 297 297 //@} End of Memory Management Functions 298 298 299 # ifndef DOXYGEN299 #ifndef DOXYGEN 300 300 301 301 /* 302 302 * Ensure that any program using malloc/realloc/free will fail to compile 303 303 */ 304 # ifndef PS_ALLOW_MALLOC305 # ifdef __GNUC__306 # pragma GCC poison malloc realloc calloc free307 # else308 # define malloc(S) _Pragma("error Use of malloc is not allowed. Use psAlloc instead.")309 # define realloc(P,S) _Pragma("error Use of realloc is not allowed. Use psRealloc instead.")310 # define calloc(S) _Pragma("error Use of calloc is not allowed. Use psAlloc instead.")311 # define free(P) _Pragma("error Use of free is not allowed. Use psFree instead.")312 # endif313 # endif314 315 # endif316 // doxygen skip317 318 #endif // end of header file304 #ifndef PS_ALLOW_MALLOC 305 #ifdef __GNUC__ 306 #pragma GCC poison malloc realloc calloc free 307 #else 308 # define malloc(S) _Pragma("error Use of malloc is not allowed. Use psAlloc instead.") 309 # define realloc(P,S) _Pragma("error Use of realloc is not allowed. Use psRealloc instead.") 310 # define calloc(S) _Pragma("error Use of calloc is not allowed. Use psAlloc instead.") 311 # define free(P) _Pragma("error Use of free is not allowed. Use psFree instead.") 312 # endif 313 # endif 314 315 # endif 316 // doxygen skip 317 318 #endif // end of header file
Note:
See TracChangeset
for help on using the changeset viewer.
