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.

Location:
trunk/psLib/src/collections
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/collections/psBitSet.c

    r1041 r1073  
    1010 *  @author Ross Harman, MHPCC
    1111 *
    12  *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2004-06-15 02:45:43 $
     12 *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2004-06-23 23:00:15 $
    1414 *
    1515 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    5555/*  FUNCTION IMPLEMENTATION - LOCAL                                          */
    5656/*****************************************************************************/
     57static void bitSetFree(psBitSet *restrict inBitSet);
     58
    5759
    5860/** Private function to create a mask.
     
    8890    numBytes = ceil(n/8.0);
    8991    newObj = psAlloc(sizeof(psBitSet));
     92    p_psMemSetDeallocator(newObj,(psFreeFcn)bitSetFree);
    9093    newObj->n = numBytes;
    9194
     
    98101}
    99102
    100 void psBitSetFree(psBitSet *restrict inBitSet)
     103static void bitSetFree(psBitSet *restrict inBitSet)
    101104{
    102105    if(inBitSet == NULL) {
     
    105108    }
    106109    psFree(inBitSet->bits);
    107     psFree(inBitSet);
    108110}
    109111
  • trunk/psLib/src/collections/psBitSet.h

    r974 r1073  
    1212 *  @author Ross Harman, MHPCC
    1313 *
    14  *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
    15  *  @date $Date: 2004-06-10 01:58:06 $
     14 *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
     15 *  @date $Date: 2004-06-23 23:00:15 $
    1616 *
    1717 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    5454psBitSet* psBitSetAlloc(
    5555    int n   /**< Number of bits in psBitSet array */
    56 );
    57 
    58 /** Free a psBitSet
    59  *
    60  *  Deletes a psBitSet array.
    61  */
    62 void psBitSetFree(
    63     psBitSet *restrict inMask  /**< Pointer to psBitSet to be deleted. */
    6456);
    6557
  • trunk/psLib/src/collections/psList.c

    r1024 r1073  
    66 *  @author Robert Daniel DeSonia, MHPCC
    77 *
    8  *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2004-06-14 19:45:46 $
     8 *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2004-06-23 23:00:15 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2828
    2929// private functions.
    30 psListElem* listGetIterator(psList* list);
    31 int listGetIteratorIndex(psList* list);
    32 void listSetIterator(psList *list, int where, bool lockList);
     30static psListElem* listGetIterator(psList* list);
     31static int listGetIteratorIndex(psList* list);
     32static void listSetIterator(psList *list, int where, bool lockList);
     33static void listFree(psList *list);
    3334
    3435
     
    3637{
    3738    psList *list = psAlloc(sizeof(psList));
     39    p_psMemSetDeallocator(list,(psFreeFcn)listFree);
    3840
    3941    list->size = 0;
     
    4143    list->iter = ITER_INIT_HEAD;
    4244    list->iterIndex = PS_LIST_HEAD;
     45
    4346    pthread_mutex_init(&(list->lock),NULL)
    4447    ;
     
    5154}
    5255
    53 void psListFree(psList *list, psFreeFcn elemFree)
     56static void listFree(psList *list)
    5457{
    5558    if (list == NULL) {
     
    6366        psListElem *next = ptr->next;
    6467
    65         p_psCustomFree(elemFree, psMemDecrRefCounter(ptr->data));
     68        psFree(ptr->data);
    6669        psFree(ptr);
    6770
     
    7578    ;
    7679
    77     psFree(list);
    7880}
    7981
  • trunk/psLib/src/collections/psList.h

    r1017 r1073  
    1010 *  @ingroup LinkedList
    1111 *
    12  *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2004-06-12 22:15:39 $
     12 *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2004-06-23 23:00:15 $
    1414 *
    1515 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    7373)
    7474;
    75 
    76 #include "psMemory.h"
    77 /** Destroys a psList linked list object.  This also frees the elements of the
    78  *  list using the psFreeFcn given, if any.  If no psFreeFcn is specified,
    79  *  the elements are just dereferenced via psMemDecrRefCounter(...).
    80  *
    81  */
    82 void psListFree(
    83     psList* restrict list,              ///< list to destroy
    84     psFreeFcn elemFree                  ///< destructor for data on list
    85 );
    8675
    8776/** Adds an element to a psList at position given.
  • trunk/psLib/src/collections/psSort.c

    r989 r1073  
    1414 *  @author Ross Harman, MHPCC
    1515 *
    16  *  @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
    17  *  @date $Date: 2004-06-10 23:15:08 $
     16 *  @version $Revision: 1.12 $ $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
     
    3333#include "psSort.h"
    3434#include "psError.h"
     35#include "psMemory.h"
    3536
    3637/******************************************************************************/
     
    242243
    243244    // Free temp memory
    244     psVectorFree(tmpVector);
     245    psFree(tmpVector);
    245246
    246247    return outVector;
  • trunk/psLib/src/collections/psSort.d

    r986 r1073  
    1 psSort.o psSort.d : psSort.c psVector.h psType.h psSort.h ../sysUtils/psError.h
     1psSort.o psSort.d : psSort.c psVector.h psType.h psSort.h ../sysUtils/psError.h \
     2  ../sysUtils/psMemory.h
  • trunk/psLib/src/collections/psVector.c

    r1008 r1073  
    88 *  @author Ross Harman, MHPCC
    99 *
    10  *  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
    11  *  @date $Date: 2004-06-12 01:33:16 $
     10 *  @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
     11 *  @date $Date: 2004-06-23 23:00:15 $
    1212 *
    1313 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    4949/*  FUNCTION IMPLEMENTATION - LOCAL                                          */
    5050/*****************************************************************************/
     51static void vectorFree(psVector *restrict psVec);
    5152
    5253/*****************************************************************************/
     
    6869    // Create vector struct
    6970    psVec = (psVector *)psAlloc(sizeof(psVector));
     71    p_psMemSetDeallocator(psVec,(psFreeFcn)vectorFree);
    7072
    7173    psVec->type.dimen = PS_DIMEN_VECTOR;
     
    132134    if(nalloc < 1) {
    133135        psError(__func__, "Invalid value for nalloc (%d)\n", nalloc);
    134         psVectorFree(in);
     136        psFree(in);
    135137        return NULL;
    136138    }
     
    154156}
    155157
    156 void psVectorFree(psVector *restrict psVec)
     158static void vectorFree(psVector *restrict psVec)
    157159{
    158160    if (psVec == NULL) {
     
    160162    }
    161163
     164    if (psVec->type.type == PS_TYPE_PTR) {
     165        for(int i = 0; i < psVec->n; i++) {
     166            psFree(psVec->data.PTR[i]);
     167            psVec->data.PTR[i] = NULL;
     168        }
     169    }
     170
    162171    psFree(psVec->data.V);
    163     psFree(psVec);
    164172}
    165173
    166 void psVectorElementFree(psVector *restrict psVec, void (*elemFree)(void *))
     174void psVectorElementFree(psVector *restrict psVec)
    167175{
    168176
     
    176184    }
    177185
    178     for(int i = 0; i < psVec->nalloc; i++) {
    179         if(elemFree == NULL) {
    180             psMemDecrRefCounter(psVec->data.PTR[i]);
    181         } else {
    182             elemFree(psMemDecrRefCounter(psVec->data.PTR[i]));
    183         }
     186    for(int i = 0; i < psVec->n; i++) {
     187        psFree(psVec->data.PTR[i]);
    184188        psVec->data.PTR[i] = NULL;
    185189    }
  • trunk/psLib/src/collections/psVector.h

    r974 r1073  
    1111 *  @author Ross Harman, MHPCC
    1212 *
    13  *  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
    14  *  @date $Date: 2004-06-10 01:58:06 $
     13 *  @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
     14 *  @date $Date: 2004-06-23 23:00:15 $
    1515 *
    1616 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    100100);
    101101
    102 /** Deallocate a vector.
    103  *
    104  * Uses psLib memory allocation functions to deallocate a vector collection of data. The vector is deallocated
    105  * according to the psType type member contained within the vector.
    106  *
    107  * @return psVector*: Pointer to psVector.
    108  *
    109  */
    110 void psVectorFree(
    111     psVector *restrict psVec  ///< Vector to free.
    112 );
    113 
    114 
    115102/** Deallocate/Dereference elements of a void pointer vector.
    116103 *
     
    122109 */
    123110void psVectorElementFree(
    124     psVector *restrict psVec,   ///< Void pointer vector to destroy.
    125     void (*elemFree)(void *)    ///< Optional callback function to remove vector elements.
     111    psVector *restrict psVec    ///< Void pointer vector to destroy.
    126112);
    127113
Note: See TracChangeset for help on using the changeset viewer.