Changeset 247 for trunk/archive/pslib/include/psMemory.h
- Timestamp:
- Mar 15, 2004, 3:20:03 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/archive/pslib/include/psMemory.h (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/archive/pslib/include/psMemory.h
r222 r247 1 1 #if !defined(PS_MEMORY_H) 2 2 #define PS_MEMORY_H 3 #include <stdio.h> 4 /** 5 * Book-keeping data for storage allocator. 6 * 7 * N.b. sizeof(psMemBlock) must be chosen such that if ptr is a pointer 8 * returned by malloc, then ((char *)ptr + sizeof(psMemBlock)) is properly 9 * aligned for all storage types. 3 4 /** \file psMemory.h 5 * \brief Memory alloc/free routines 6 * \ingroup SystemGroup 7 */ 8 9 /** Book-keeping data for storage allocator. 10 * N.b. sizeof(psMemBlock) must be chosen such that if ptr is a pointer 11 * returned by malloc, then ((char *)ptr + sizeof(psMemBlock)) is properly 12 * aligned for all storage types. 10 13 */ 11 14 typedef struct { … … 18 21 } psMemBlock; 19 22 20 /** */23 /** prototype of a basic callback used by memory functions */ 21 24 typedef int (*psMemCallback)(const psMemBlock *ptr); 22 typedef void (*psMemProblemCallback)(const psMemBlock *ptr, 23 const char *file, int lineno); 25 26 /** prototype of a callback used in error conditions */ 27 typedef void (*psMemProblemCallback)(const psMemBlock *ptr, const char *file, int lineno); 28 29 /** prototype of a callback used when memory runs out */ 24 30 typedef void *(*psMemExhaustedCallback)(size_t size); 25 31 26 32 /*****************************************************************************/ 27 33 28 /** Fake for p_psAlloc */ 29 void *psAlloc(size_t size //!< Size required 30 ); 31 /** Fake for p_psRealloc */ 32 void *psRealloc(void *ptr, //!< Pointer to re-allocate 33 size_t size //!< Size required 34 ); 35 /** Fake for p_psFree */ 36 void psFree(void *ptr //!< Pointer to free 37 ); 38 39 /** Memory allocation */ 34 /** Memory allocation. Underlying private function called by macro psAlloc. */ 40 35 void *p_psAlloc(size_t size, //!< Size required 41 36 const char *file, //!< File of call … … 43 38 ); 44 39 45 /** Memory re-allocation */40 /** Memory re-allocation. Underlying private function called by macro psRealloc. */ 46 41 void *p_psRealloc(void *ptr, //!< Pointer to re-allocate 47 42 size_t size, //!< Size required … … 50 45 ); 51 46 52 /** Free memory */47 /** Free memory. Underlying private function called by macro psFree. */ 53 48 void p_psFree(void *ptr, //!< Pointer to free 54 49 const char *file, //!< File of call … … 56 51 ); 57 52 58 /** psAlloc sends file and line number to p_psAlloc*/53 /** Memory allocation. psAlloc sends file and line number to p_psAlloc. */ 59 54 #define psAlloc(size) p_psAlloc(size, __FILE__, __LINE__) 60 /** psRealloc sends file and line number to p_psRealloc */ 55 56 /** Memory re-allocation. psRealloc sends file and line number to p_psRealloc. */ 61 57 #define psRealloc(ptr, size) p_psRealloc(ptr, size, __FILE__, __LINE__) 62 /** psFree sends file and line number to p_psFree */ 58 59 /** Free memory. psFree sends file and line number to p_psFree. */ 63 60 #define psFree(size) p_psFree(size, __FILE__, __LINE__) 64 61 65 /* 66 * Ensure that any program using malloc/realloc/free will fail to compile 67 */ 62 /** prevent the use of 'malloc'. malloc is re-defined to throw an error in the C preprocessor */ 68 63 #define malloc(S) for 64 65 /** prevent the use of 'realloc'. realloc is re-defined to throw an error in the C preprocessor */ 69 66 #define realloc(P,S) for 67 68 /** prevent the use of 'free'. free is re-defined to throw an error in the C preprocessor */ 70 69 #define free(P) for 71 70 … … 112 111 long psMemSetAllocateID(long id); //!< set p_psMemAllocateID to id 113 112 long psMemSetFreeID(long id); //!< set p_psMemFreeID to id 113 114 114 #endif
Note:
See TracChangeset
for help on using the changeset viewer.
