IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 23, 2004, 1:00:17 PM (22 years ago)
Author:
desonia
Message:

Changed the means of deallocation of memory. ps_Alloc now registers an optional free function to handle any additional processing of a memory object.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/sys/psMemory.h

    r978 r1073  
    1414 *  @ingroup MemoryManagement
    1515 *
    16  *  @version $Revision: 1.18 $ $Name: not supported by cvs2svn $
    17  *  @date $Date: 2004-06-10 02:09:57 $
     16 *  @version $Revision: 1.19 $ $Name: not supported by cvs2svn $
     17 *  @date $Date: 2004-06-23 23:00:15 $
    1818 *
    1919 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    5050/// typedef for a memory block's reference count. Guaranteed to be some variety of integer.
    5151typedef unsigned long psReferenceCount;
     52
     53/// typedef for deallocator.
     54typedef void (*psFreeFcn)(void* ptr);
    5255
    5356/** Book-keeping data for storage allocator.
     
    5861typedef struct psMemBlock
    5962{
    60     const void* startblock;             ///< initialised to p_psMEMMAGIC
    61     struct psMemBlock* previousBlock;   ///< previous block in allocation list
    62     struct psMemBlock* nextBlock;       ///< next block allocation list
    63     size_t  userMemorySize;             ///< the size of the user-portion of the memory block
    64     const psMemoryId id;                ///< a unique ID for this allocation
    65     const char* file;                   ///< set from __FILE__ in e.g. p_psAlloc
    66     const int lineno;                   ///< set from __LINE__ in e.g. p_psAlloc
    67     pthread_mutex_t   refCounterMutex;  ///< mutex to ensure exclusive access to reference counter
    68     psReferenceCount refCounter;        ///< how many times pointer is referenced
    69     const void* endblock;               ///< initialised to p_psMEMMAGIC
     63    const void* startblock;            ///< initialised to p_psMEMMAGIC
     64    struct psMemBlock* previousBlock;  ///< previous block in allocation list
     65    struct psMemBlock* nextBlock;      ///< next block allocation list
     66    psFreeFcn freeFcn;                 ///< deallocator.  If NULL, use generic deallocation.
     67    size_t  userMemorySize;            ///< the size of the user-portion of the memory block
     68    const psMemoryId id;               ///< a unique ID for this allocation
     69    const char* file;                  ///< set from __FILE__ in e.g. p_psAlloc
     70    const int lineno;                  ///< set from __LINE__ in e.g. p_psAlloc
     71    pthread_mutex_t   refCounterMutex; ///< mutex to ensure exclusive access to reference counter
     72    psReferenceCount refCounter;       ///< how many times pointer is referenced
     73    const void* endblock;              ///< initialised to p_psMEMMAGIC
    7074}
    7175psMemBlock;
     
    114118);
    115119
    116 typedef void (*psFreeFcn)(void* ptr);
    117 
    118120/** Memory allocation.  This operates much like malloc(), but is guaranteed to return a non-NULL value.
    119121 *
    120122 *  @return void* pointer to the allocated buffer. This will not be NULL.
    121  *  @see psFree
     123 *  @see psFree 
    122124 */
    123125#ifdef DOXYGEN
     
    131133    int lineno                      ///< Line number of call
    132134);
     135
     136void p_psMemSetDeallocator(void* ptr, psFreeFcn freeFcn);
     137psFreeFcn p_psMemGetDeallocator(void* ptr);
     138
    133139/// Memory allocation. psAlloc sends file and line number to p_psAlloc.
    134140#define psAlloc(size) p_psAlloc(size, __FILE__, __LINE__)
     
    282288);
    283289
    284 #define PS_FREE     (void*)1
    285 
    286290//@} End of Memory Management Functions
    287291
    288 
    289292#ifndef DOXYGEN
    290 
    291 void p_psCustomFree(psFreeFcn fcn,void* ptr);
    292293
    293294/*
Note: See TracChangeset for help on using the changeset viewer.