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/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    }
Note: See TracChangeset for help on using the changeset viewer.