This is the generic memory management system put inbetween the user's high level code and the OS-level memory allocation routines. This system adds such features as callback routines for memory error events, tracing capabilities, and reference counting.
Robert Lupton, Princeton University
Definition in file psMemory.h.
#include <stdio.h>
#include <pthread.h>
#include "psType.h"
Include dependency graph for psMemory.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.
Typedefs | |
| typedef psU64 | psMemoryId |
| typedef for memory identification numbers. Guaranteed to be some variety of integer. | |
| typedef psU64 | psReferenceCount |
| typedef for a memory block's reference count. Guaranteed to be some variety of integer. | |
| typedef void(* | psFreeFcn )(psPtr ptr) |
| typedef for deallocator. | |
| typedef psMemBlock | psMemBlock |
| Book-keeping data for storage allocator. | |
| typedef psMemoryId(* | psMemAllocateCallback )(const psMemBlock *ptr) |
| prototype of a basic callback used by memory functions | |
| typedef psMemoryId(* | psMemFreeCallback )(const psMemBlock *ptr) |
| prototype of memory free callback used by memory functions | |
| typedef void(* | psMemProblemCallback )(const psMemBlock *ptr, const char *file, psS32 lineno) |
| prototype of a callback used in error conditions | |
| typedef psPtr(* | psMemExhaustedCallback )(size_t size) |
| prototype of a callback function used when memory runs out | |
Functions | |
| psPtr | psAlloc (size_t size) |
| Memory allocation. | |
| void | psMemSetDeallocator (psPtr ptr, psFreeFcn freeFcn) |
| Set the deallocator routine. | |
| psFreeFcn | psMemGetDeallocator (psPtr ptr) |
| Get the deallocator routine. | |
| void | p_psMemSetPersistent (psPtr ptr, psBool value) |
| Set the memory as persistent so that it is ignored when detecting memory leaks. | |
| psBool | p_psMemGetPersistent (psPtr ptr) |
| Get the memory's persistent flag. | |
| psPtr | psRealloc (psPtr ptr, size_t size) |
| Memory re-allocation. | |
| void | psFree (psPtr ptr) |
| Free memory. | |
| psS32 | psMemCheckLeaks (psMemoryId id0, psMemBlock ***arr, FILE *fd, psBool persistence) |
| Check for memory leaks. | |
| psS32 | psMemCheckCorruption (psBool abort_on_error) |
| Check for memory corruption. | |
| psReferenceCount | psMemGetRefCounter (psPtr vptr) |
| Return reference counter. | |
| psPtr | psMemIncrRefCounter (psPtr vptr) |
| Increment reference counter and return the pointer. | |
| psPtr | psMemDecrRefCounter (psPtr vptr) |
| Decrement reference counter and return the pointer. | |
| psMemProblemCallback | psMemProblemCallbackSet (psMemProblemCallback func) |
| Set callback for problems. | |
| psMemExhaustedCallback | psMemExhaustedCallbackSet (psMemExhaustedCallback func) |
| Set callback for out-of-memory. | |
| psMemAllocateCallback | psMemAllocateCallbackSet (psMemAllocateCallback func) |
| Set call back for when a particular memory block is allocated. | |
| psMemFreeCallback | psMemFreeCallbackSet (psMemFreeCallback func) |
| Set call back for when a particular memory block is freed. | |
| psMemoryId | psMemGetId (void) |
| get next memory ID | |
| psMemoryId | psMemAllocateCallbackSetID (psMemoryId id) |
| set p_psMemAllocateID to specific id | |
| psMemoryId | psMemFreeCallbackSetID (psMemoryId id) |
| set p_psMemFreeID to id | |
1.4.1