Changeset 1569
- Timestamp:
- Aug 18, 2004, 3:08:06 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
r753 r1569 10 10 // Structures *********************************************************** 11 11 12 /** A function that frees an allocated pointer */ 13 typedef void (*psFreeFcn)(void* ptr); 14 15 /** Memory ID number */ 16 typedef unsigned long psMemoryId; 17 18 /** Reference counter number */ 19 typedef unsigned long psReferenceCount; 20 12 21 /** Book-keeping data for storage allocator. 13 22 * N.b. sizeof(psMemBlock) must be chosen such that if ptr is a pointer … … 16 25 */ 17 26 typedef struct { 18 const void *startblock; ///< initialised to p_psMEMMAGIC 19 const unsigned long id; ///< a unique ID for this allocation 20 const char *file; ///< set from __FILE__ in e.g. p_psAlloc 21 const int lineno; ///< set from __LINE__ in e.g. p_psAlloc 22 int refCounter; ///< how many times pointer is referenced 23 const void **endpost; ///< initialised to p_psMEMMAGIC 24 const void *endblock; ///< initialised to p_psMEMMAGIC 27 const void* startblock; ///< initialised to p_psMEMMAGIC 28 struct psMemBlock* previousBlock; ///< previous block in allocation list 29 struct psMemBlock* nextBlock; ///< next block allocation list 30 psFreeFcn freeFcn; ///< deallocator. If NULL, use generic deallocation. 31 size_t userMemorySize; ///< the size of the user-portion of the memory block 32 const psMemoryId id; ///< a unique ID for this allocation 33 const char* file; ///< set from __FILE__ in e.g. p_psAlloc 34 const int lineno; ///< set from __LINE__ in e.g. p_psAlloc 35 pthread_mutex_t refCounterMutex; ///< mutex to ensure exclusive access to reference counter 36 psReferenceCount refCounter; ///< how many times pointer is referenced 37 const void* endblock; ///< initialised to p_psMEMMAGIC 25 38 } psMemBlock; 26 39 27 40 /// prototype of a basic callback used by memory functions 28 typedef long(*psMemAllocateCallback)(const psMemBlock *ptr);41 typedef psMemoryId (*psMemAllocateCallback)(const psMemBlock *ptr); 29 42 30 43 /// prototype of memory free callback used by memory functions 31 typedef long(*psMemFreeCallback)(const psMemBlock *ptr);44 typedef psMemoryId (*psMemFreeCallback)(const psMemBlock *ptr); 32 45 33 46 /// prototype of a callback used in error conditions … … 41 54 * \{ 42 55 */ 56 57 /** Set the fcn pointer to the appropriate ps*Free function. If NULL, then a generic free functionality is 58 * used (i.e., the old psFree functionality). 59 */ 60 void p_psMemSetDeallocator(void* ptr, psFreeFcn func); 61 62 /** retrieves the function pointer to the higher-level free function to be used. If NULL, then the 63 * traditional psFree functionality shall be used. 64 */ 65 freeFcn p_psMemGetDeallocator(void* ptr); 43 66 44 67 /// Memory allocation. Underlying private function called by macro psAlloc. … … 62 85 63 86 /// Check for memory leaks 64 int psMemCheckLeaks( int id0,///< don't list blocks with id < id087 int psMemCheckLeaks(psMemoryId id0, ///< don't list blocks with id < id0 65 88 psMemBlock ***arr, ///< pointer to array of pointers to leaked blocks, or NULL 66 89 FILE *fd) ///< print list of leaks to fd (or NULL) … … 68 91 69 92 /// Check for memory corruption 70 int psMemCheckCorruption( intabort_on_error) ///< Abort on detecting corruption?93 int psMemCheckCorruption(bool abort_on_error) ///< Abort on detecting corruption? 71 94 ; 72 95 73 96 /// Return reference counter 74 int psMemGetRefCounter(void *vptr) ///< Pointer to get refCounter for97 psReferenceCount psMemGetRefCounter(void *vptr) ///< Pointer to get refCounter for 75 98 ; 76 99 … … 99 122 ; 100 123 124 /** Default callback functions */ 125 psMemExhaustedCallback psMemExhaustedCallbackDefault; 126 psMemProblemCallback psMemProblemCallbackDefault; 127 psMemAllocateCallback psMemAllocateCallbackDefault; 128 psMemFreeCallback psMemFreeCallbackDefault; 129 101 130 /// get next memory ID 102 intpsMemGetId(void)131 psMemoryId psMemGetId(void) 103 132 ; 104 133 105 134 /// set p_psMemAllocateID to id 106 long psMemAllocateIDSet(long id)///< ID to set135 psMemoryId psMemAllocateCallbackSetID(psMemoryId id) ///< ID to set 107 136 ; 108 137 109 138 /// set p_psMemFreeID to id 110 long psMemFreeIDSet(long id)///< ID to set139 psMemoryId psMemFreeCallbackSetID(psMemoryId id) ///< ID to set 111 140 ; 112 141
Note:
See TracChangeset
for help on using the changeset viewer.
