Changeset 196 for trunk/archive/pslib/include/psMemory.h
- Timestamp:
- Mar 9, 2004, 5:19:15 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/archive/pslib/include/psMemory.h (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/archive/pslib/include/psMemory.h
r181 r196 2 2 #define PS_MEMORY_H 3 3 #include <stdio.h> 4 /* 5 * Book-keeping data for storage allocator 4 /** 5 * Book-keeping data for storage allocator. 6 6 * 7 7 * N.b. sizeof(psMemBlock) must be chosen such that if ptr is a pointer … … 10 10 */ 11 11 typedef struct { 12 const void *magic0; // initialised to p_psMEMMAGIC13 const unsigned long id; // a unique ID for this allocation14 const char *file; // set from __FILE__ in e.g. p_psAlloc15 const int lineno; // set from __LINE__ in e.g. p_psAlloc16 int refCounter; // how many times pointer is referenced17 const void *magic; // initialised to p_psMEMMAGIC12 const void *magic0; //!< initialised to p_psMEMMAGIC 13 const unsigned long id; //!< a unique ID for this allocation 14 const char *file; //!< set from __FILE__ in e.g. p_psAlloc 15 const int lineno; //!< set from __LINE__ in e.g. p_psAlloc 16 int refCounter; //!< how many times pointer is referenced 17 const void *magic; //!< initialised to p_psMEMMAGIC 18 18 } psMemBlock; 19 19 20 /** */ 20 21 typedef int (*psMemCallback)(const psMemBlock *ptr); 21 22 typedef void (*psMemProblemCallback)(const psMemBlock *ptr, … … 25 26 /*****************************************************************************/ 26 27 27 void *psAlloc(size_t size); 28 void *psRealloc(void *ptr, size_t size); 29 void psFree(void *ptr); 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 ); 30 38 31 void *p_psAlloc(size_t size, const char *file, int lineno); 32 void *p_psRealloc(void *ptr, size_t size, const char *file, int lineno); 33 void p_psFree(void *ptr, const char *file, int lineno); 39 /** Memory allocation */ 40 void *p_psAlloc(size_t size, //!< Size required 41 const char *file, //!< File of call 42 int lineno //!< Line number of call 43 ); 34 44 45 /** Memory re-allocation */ 46 void *p_psRealloc(void *ptr, //!< Pointer to re-allocate 47 size_t size, //!< Size required 48 const char *file, //!< File of call 49 int lineno //!< Line number of call 50 ); 51 52 /** Free memory */ 53 void p_psFree(void *ptr, //!< Pointer to free 54 const char *file, //!< File of call 55 int lineno //!< Line number of call 56 ); 57 58 /** psAlloc sends file and line number to p_psAlloc */ 35 59 #define psAlloc(size) p_psAlloc(size, __FILE__, __LINE__) 60 /** psRealloc sends file and line number to p_psRealloc */ 36 61 #define psRealloc(ptr, size) p_psRealloc(ptr, size, __FILE__, __LINE__) 62 /** psFree sends file and line number to p_psFree */ 37 63 #define psFree(size) p_psFree(size, __FILE__, __LINE__) 38 64 39 65 /*****************************************************************************/ 40 /* 41 * Checks of memory system 42 */ 43 int psMemCheckLeaks( 44 int id0, // don't list blocks with id < id045 psMemBlock ***arr, // pointer to array of pointers to 46 // leaked blocks, or NULL 47 FILE *fd); // print list of leaks to fd (or NULL) 48 int psMemCheckCorruption(int abort_on_error);66 /** Check for memory leaks */ 67 int psMemCheckLeaks(int id0, //!< don't list blocks with id < id0 68 psMemBlock ***arr, //!< pointer to array of pointers to leaked blocks, or NULL 69 FILE *fd //!< print list of leaks to fd (or NULL) 70 ); 71 72 /** Check for memory corruption */ 73 int psMemCheckCorruption(int abort_on_error //!< Abort on detecting corruption? 74 ); 49 75 50 76 /*****************************************************************************/ 51 /* 52 * Manipulate reference counter 53 */ 54 int psMemGetRefCounter(void *vptr); // return refCounter 55 void *psMemIncrRefCounter(void *vptr); // increment refCounter and return vptr 56 void *psMemDecrRefCounter(void *vptr); // decrement refCounter and return vptr 77 78 /** Return reference counter */ 79 int psMemGetRefCounter(void *vptr //!< Pointer to get refCounter for 80 ); 81 /** Increment reference counter and return the pointer */ 82 void *psMemIncrRefCounter(void *vptr //!< Pointer to increment refCounter, and return 83 ); 84 /** Decrement reference counter and return the pointer */ 85 void *psMemDecrRefCounter(void *vptr //!< Pointer to decrement refCounter, and return 86 ); 57 87 58 88 /*****************************************************************************/ … … 60 90 * Functions to set and control callbacks 61 91 */ 62 psMemProblemCallback psMemProblemSetCB(psMemProblemCallback func);63 psMemExhaustedCallback psMemExhaustedSetCB(psMemExhaustedCallback func);64 92 65 psMemCallback psMemAllocateSetCB(psMemCallback func); 66 psMemCallback psMemFreeSetCB(psMemCallback func); 93 /** Set callback for problems */ 94 psMemProblemCallback psMemProblemSetCB(psMemProblemCallback func //!< Function to run 95 ); 96 psMemExhaustedCallback psMemExhaustedSetCB(psMemExhaustedCallback func); //!< set call back for exhausted 97 //!< memory 67 98 68 int psMemGetId(void); // get next memory ID 69 long psMemSetAllocateID(long id); // set p_psMemAllocateID to id 70 long psMemSetFreeID(long id); // set p_psMemFreeID to id 99 psMemCallback psMemAllocateSetCB(psMemCallback func); //!< Set call back for when a particular memory block is 100 //!< allocated 101 psMemCallback psMemFreeSetCB(psMemCallback func); //!< set call back for when a particular memory block is 102 //!< freed 103 104 int psMemGetId(void); //!< get next memory ID 105 long psMemSetAllocateID(long id); //!< set p_psMemAllocateID to id 106 long psMemSetFreeID(long id); //!< set p_psMemFreeID to id 71 107 #endif
Note:
See TracChangeset
for help on using the changeset viewer.
