Index: /trunk/archive/pslib/include/psMemory.h
===================================================================
--- /trunk/archive/pslib/include/psMemory.h	(revision 1568)
+++ /trunk/archive/pslib/include/psMemory.h	(revision 1569)
@@ -10,4 +10,13 @@
 // Structures ***********************************************************
 
+/** A function that frees an allocated pointer */
+typedef void (*psFreeFcn)(void* ptr);
+
+/** Memory ID number */
+typedef unsigned long psMemoryId;
+
+/** Reference counter number */
+typedef unsigned long psReferenceCount;
+
 /** Book-keeping data for storage allocator.
  *  N.b. sizeof(psMemBlock) must be chosen such that if ptr is a pointer
@@ -16,18 +25,22 @@
  */
 typedef struct {
-    const void *startblock;		///< initialised to p_psMEMMAGIC
-    const unsigned long id;		///< a unique ID for this allocation
-    const char *file;			///< set from __FILE__ in e.g. p_psAlloc
-    const int lineno;			///< set from __LINE__ in e.g. p_psAlloc
-    int refCounter;			///< how many times pointer is referenced
-    const void **endpost;		///< initialised to p_psMEMMAGIC
-    const void *endblock;		///< initialised to p_psMEMMAGIC
+    const void* startblock;             ///< initialised to p_psMEMMAGIC
+    struct psMemBlock* previousBlock;   ///< previous block in allocation list
+    struct psMemBlock* nextBlock;       ///< next block allocation list
+    psFreeFcn freeFcn;                  ///< deallocator.  If NULL, use generic deallocation.
+    size_t  userMemorySize;             ///< the size of the user-portion of the memory block
+    const psMemoryId id;                ///< a unique ID for this allocation
+    const char* file;                   ///< set from __FILE__ in e.g. p_psAlloc
+    const int lineno;                   ///< set from __LINE__ in e.g. p_psAlloc
+    pthread_mutex_t   refCounterMutex;  ///< mutex to ensure exclusive access to reference counter
+    psReferenceCount refCounter;        ///< how many times pointer is referenced
+    const void* endblock;               ///< initialised to p_psMEMMAGIC
 } psMemBlock;
 
 /// prototype of a basic callback used by memory functions 
-typedef long (*psMemAllocateCallback)(const psMemBlock *ptr);
+typedef psMemoryId (*psMemAllocateCallback)(const psMemBlock *ptr);
 
 /// prototype of memory free callback used by memory functions 
-typedef long (*psMemFreeCallback)(const psMemBlock *ptr);
+typedef psMemoryId (*psMemFreeCallback)(const psMemBlock *ptr);
 
 /// prototype of a callback used in error conditions 
@@ -41,4 +54,14 @@
  *  \{
  */
+
+/** Set the fcn pointer to the appropriate ps*Free function.  If NULL, then a generic free functionality is
+ * used (i.e., the old psFree functionality).
+ */
+void p_psMemSetDeallocator(void* ptr, psFreeFcn func);
+
+/** retrieves the function pointer to the higher-level free function to be used.  If NULL, then the
+ * traditional psFree functionality shall be used.
+ */
+freeFcn p_psMemGetDeallocator(void* ptr);
 
 /// Memory allocation. Underlying private function called by macro psAlloc. 
@@ -62,5 +85,5 @@
 
 /// Check for memory leaks 
-int psMemCheckLeaks(int id0,		///< don't list blocks with id < id0
+int psMemCheckLeaks(psMemoryId id0,	///< don't list blocks with id < id0
 		    psMemBlock ***arr,	///< pointer to array of pointers to leaked blocks, or NULL
 		    FILE *fd)		///< print list of leaks to fd (or NULL)
@@ -68,9 +91,9 @@
 
 /// Check for memory corruption 
-int psMemCheckCorruption(int abort_on_error) ///< Abort on detecting corruption?
+int psMemCheckCorruption(bool abort_on_error) ///< Abort on detecting corruption?
 ;
 
 /// Return reference counter 
-int psMemGetRefCounter(void *vptr)	///< Pointer to get refCounter for
+psReferenceCount psMemGetRefCounter(void *vptr)	///< Pointer to get refCounter for
 ;
 
@@ -99,14 +122,20 @@
 ;
 
+/** Default callback functions */
+psMemExhaustedCallback psMemExhaustedCallbackDefault;
+psMemProblemCallback psMemProblemCallbackDefault;
+psMemAllocateCallback psMemAllocateCallbackDefault;
+psMemFreeCallback psMemFreeCallbackDefault;
+
 /// get next memory ID 
-int psMemGetId(void)
+psMemoryId psMemGetId(void)
 ;
 
 /// set p_psMemAllocateID to id 
-long psMemAllocateIDSet(long id)	///< ID to set
+psMemoryId psMemAllocateCallbackSetID(psMemoryId id) ///< ID to set
 ;
 
 /// set p_psMemFreeID to id 
-long psMemFreeIDSet(long id)		///< ID to set
+psMemoryId psMemFreeCallbackSetID(psMemoryId id) ///< ID to set
 ;
 
