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 unsigned long | psMemId |
| typedef for memory identification numbers. Guaranteed to be some variety of integer. | |
| typedef unsigned long | psReferenceCount |
| typedef for a memory block's reference count. Guaranteed to be some variety of integer. | |
| typedef void(* | psFreeFunc )(void *ptr) |
| typedef for deallocator. | |
| typedef psMemBlock | psMemBlock |
| Book-keeping data for storage allocator. | |
| typedef psMemId(* | psMemAllocCallback )(const psMemBlock *ptr) |
| prototype of a basic callback used by memory functions | |
| typedef psMemId(* | psMemFreeCallback )(const psMemBlock *ptr) |
| prototype of memory free callback used by memory functions | |
| typedef void(* | psMemProblemCallback )(psMemBlock *ptr, const char *filename, unsigned int 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, psFreeFunc freeFunc) |
| Set the deallocator routine. | |
| psFreeFunc | psMemGetDeallocator (const psPtr ptr) |
| Get the deallocator routine. | |
| bool | psMemCheckType (psDataType type, psPtr ptr) |
| Checks the deallocator to see if the pointer matches the desired datatype. | |
| void | p_psMemSetPersistent (psPtr ptr, bool value) |
| Set the memory as persistent so that it is ignored when detecting memory leaks. | |
| bool | 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. | |
| int | psMemCheckLeaks (psMemId id0, psMemBlock ***array, FILE *fd, bool persistence) |
| Check for memory leaks. | |
| int | psMemCheckCorruption (bool abort_on_error) |
| Check for memory corruption. | |
| psReferenceCount | psMemGetRefCounter (const psPtr ptr) |
| Return reference counter. | |
| psPtr | psMemIncrRefCounter (const psPtr ptr) |
| Increment reference counter and return the pointer. | |
| psPtr | psMemDecrRefCounter (psPtr ptr) |
| 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. | |
| psMemAllocCallback | psMemAllocCallbackSet (psMemAllocCallback 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. | |
| psMemId | psMemGetId (void) |
| get next memory ID | |
| psMemId | psMemAllocCallbackSetID (psMemId id) |
| set p_psMemAllocID to specific id | |
| psMemId | psMemFreeCallbackSetID (psMemId id) |
| set p_psMemFreeID to id | |
1.4.2