Collaboration diagram for MemoryManagement:
|
Data Structures | |
| struct | psMemBlock |
| Book-keeping data for storage allocator. More... | |
Defines | |
| #define | P_PS_MEMMAGIC (psU32)0xdeadbeef |
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 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 *file, 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 | psMemSetThreadSafety (bool safe) |
| Activate or Deactivate thread safety and mutex locking in the memory management. | |
| bool | psMemGetThreadSafety (void) |
| Get the current state of thread safety and mutex locking in the memory management. | |
| void | psMemSetPersistent (psPtr ptr, bool value,) |
| Set the memory as persistent so that it is ignored when detecting memory leaks. | |
| bool | p_psMemAllocatePersistent (bool is_persistent) |
| Set whether allocated memory is persistent Should all memory allocated be persistent? | |
| bool | 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 (FILE *output, 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. | |
| 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 | psMemGetLastId (void) |
| get the last memory ID used | |
| psMemId | psMemAllocCallbackSetID (psMemId id) |
| set p_psMemAllocID to specific id | |
| psMemId | psMemFreeCallbackSetID (psMemId id) |
| set p_psMemFreeID to id | |
| size_t | psMemStats (const bool print, size_t *allocated, size_t *persistent) |
| return statistics on memory usage persistent memory that's currently allocated | |
| int | psMemBlockPrint (FILE *output, const psMemBlock *memBlock) |
| print detailed information about a psMemBlock | |
| #define P_PS_MEMMAGIC (psU32)0xdeadbeef |
Definition at line 37 of file psMemory.h.
| typedef void(*) psFreeFunc(void *ptr) |
| typedef psMemId(*) psMemAllocCallback(const psMemBlock *ptr) |
prototype of a basic callback used by memory functions
Definition at line 85 of file psMemory.h.
| typedef psPtr(*) psMemExhaustedCallback(size_t size) |
prototype of a callback function used when memory runs out
Definition at line 116 of file psMemory.h.
| typedef psMemId(*) psMemFreeCallback(const psMemBlock *ptr) |
prototype of memory free callback used by memory functions
Definition at line 93 of file psMemory.h.
| typedef unsigned long psMemId |
typedef for memory identification numbers. Guaranteed to be some variety of integer.
Definition at line 40 of file psMemory.h.
| typedef void(*) psMemProblemCallback(psMemBlock *ptr,const char *file,unsigned int lineno) |
prototype of a callback used in error conditions
This callback should not try to call psAlloc or psFree.
Definition at line 103 of file psMemory.h.
| typedef unsigned long psReferenceCount |
typedef for a memory block's reference count. Guaranteed to be some variety of integer.
Definition at line 43 of file psMemory.h.
| bool p_psMemAllocatePersistent | ( | bool | is_persistent | ) |
Set whether allocated memory is persistent Should all memory allocated be persistent?
Set whether allocated memory is persistent. The defeault is false.
| psPtr psAlloc | ( | size_t | size | ) |
Memory allocation.
This operates much like malloc(), but is guaranteed to return a non-NULL value.
| size | Size required |
| void psFree | ( | psPtr | ptr | ) |
| psMemAllocCallback psMemAllocCallbackSet | ( | psMemAllocCallback | func | ) |
Set call back for when a particular memory block is allocated.
A private variable, p_psMemAllocID, can be used to trace the allocation and freeing of specific memory blocks. If p_psMemAllocID is set and a memory block with that ID is allocated, psMemAllocCallback is called just before memory is returned to the calling function.
| func | Function to run at memory allocation of specific mem block |
set p_psMemAllocID to specific id
A private variable, p_psMemAllocID, can be used to trace the allocation and freeing of specific memory blocks. If p_psMemAllocID is set and a memory block with that ID is allocated, psMemAllocCallback is called just before memory is returned to the calling function.
| id | ID to set |
| int psMemBlockPrint | ( | FILE * | output, | |
| const psMemBlock * | memBlock | |||
| ) |
print detailed information about a psMemBlock
This function prints a detailed description of a psMemBlock to output.
| output | FILE to write information too |
| memBlock | psMemBlock to be examined |
| int psMemCheckCorruption | ( | FILE * | output, | |
| bool | abort_on_error | |||
| ) |
Check for memory corruption.
Scans all currently allocated memory buffers and checks for corruptions, i.e., invalid markers that signify a buffer under/overflow.
| output | FILE to write corrupted blocks too |
| abort_on_error | Abort on detecting corruption? |
| int psMemCheckLeaks | ( | psMemId | id0, | |
| psMemBlock *** | array, | |||
| FILE * | fd, | |||
| bool | persistence | |||
| ) |
Check for memory leaks.
This scans for allocated memory buffers not freed with an ID not less than id0. This is used to check for memory leaks by:
If memory leaks are found, the Memory Problem callback will be called as well.
| id0 | don't list blocks with id < id0 |
| array | pointer to array of pointers to leaked blocks, or NULL |
| fd | print list of leaks to fd (or NULL) |
| persistence | make check across all object even persistent ones |
Decrement reference counter and return the pointer.
| ptr | Pointer to decrement refCounter, and return |
| psMemExhaustedCallback psMemExhaustedCallbackSet | ( | psMemExhaustedCallback | func | ) |
Set callback for out-of-memory.
If not enough memory is available to satisfy a request by psAlloc or psRealloc, these functions attempt to find an alternative solution by calling the psMemExhaustedCallback, a function which may be set by the programmer in appropriate circumstances, rather than immediately fail. The typical use of such a feature may be when a program needs a large chunk of memory to do an operation, but the exact size is not critical. This feature gives the programmer the opportunity to make a smaller request and try again, limiting the size of the operating buffer.
| func | Function to run at memory exhaustion |
| psMemFreeCallback psMemFreeCallbackSet | ( | psMemFreeCallback | func | ) |
Set call back for when a particular memory block is freed.
A private variable, p_psMemFreeID, can be used to trace the freeing of specific memory blocks. If p_psMemFreeID is set and the memory block with the ID is about to be freed, the psMemFreeCallback callback is called just before the memory block is freed.
| func | Function to run at memory free of specific mem block |
set p_psMemFreeID to id
A private variable, p_psMemFreeID, can be used to trace the freeing of specific memory blocks. If p_psMemFreeID is set and the memory block with the ID is about to be freed, the psMemFreeCallback callback is called just before the memory block is freed.
| id | ID to set |
| psFreeFunc psMemGetDeallocator | ( | const psPtr | ptr | ) |
Get the deallocator routine.
This function returns the deallocator for a memory block. A deallocator routine can optionally be assigned to a memory block to ensure that associated memory blocks also get freed, e.g., memory buffers referenced within a struct.
| ptr | the memory block |
| psMemId psMemGetId | ( | void | ) |
get next memory ID
| psMemId psMemGetLastId | ( | void | ) |
get the last memory ID used
| bool psMemGetPersistent | ( | psPtr | ptr | ) |
Get the memory's persistent flag.
Checks if a memory block has been marked as persistent by p_psMemSetPresistent.
Memory marked as persistent is excluded from memory leak checks.
| ptr | the memory block to check. |
| psReferenceCount psMemGetRefCounter | ( | const psPtr | ptr | ) |
Return reference counter.
| ptr | Pointer to get refCounter for |
| bool psMemGetThreadSafety | ( | void | ) |
Get the current state of thread safety and mutex locking in the memory management.
psMemGetThreadSafety shall return the current state of thread safety in the memory management system.
Increment reference counter and return the pointer.
| ptr | Pointer to increment refCounter, and return |
| void psMemSetDeallocator | ( | psPtr | ptr, | |
| psFreeFunc | freeFunc | |||
| ) |
Set the deallocator routine.
A deallocator routine can optionally be assigned to a memory block to ensure that associated memory blocks also get freed, e.g., memory buffers referenced within a struct.
| ptr | the memory block to operate on |
| freeFunc | the function to be executed at deallocation |
| void psMemSetPersistent | ( | psPtr | ptr, | |
| bool | value | |||
| ) |
Set the memory as persistent so that it is ignored when detecting memory leaks.
Used to mark a memory block as persistent data within the library, i.e., non user-level data used to hold psLib's state or cache data. Such examples of this class of memory is psTrace's trace-levels and dynamic error codes.
Memory marked as persistent is excluded from memory leak checks.
| ptr | the memory block to operate on |
| value | true if memory is persistent, otherwise false |
| bool psMemSetThreadSafety | ( | bool | safe | ) |
Activate or Deactivate thread safety and mutex locking in the memory management.
psMemThreadSafety shall turn on thread safety in the memory management functions if safe is true, and deactivate all mutex locking in the memory management functions if safe is false. The function shall return the previous value of the thread safety. Note that the default behaviour of the library shall be for the locking to be performed.
| safe | boolean for turning on/off thread safety |
| size_t psMemStats | ( | const bool | print, | |
| size_t * | allocated, | |||
| size_t * | persistent | |||
| ) |
return statistics on memory usage persistent memory that's currently allocated
| print details as they're found? | |
| allocated | memory that's currently allocated (but not persistent) |
1.5.1