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/test/collections/tst_psVector_03.c

    r867 r1073  
    1212 *  @author  Ross Harman, MHPCC
    1313 *
    14  *  @version $Revision: 1.4 $  $Name: not supported by cvs2svn $
    15  *  @date  $Date: 2004-06-04 19:51:49 $
     14 *  @version $Revision: 1.5 $  $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
     
    2828}
    2929testStruct;
    30 
    31 static void freeData(void *data)
    32 {
    33     psFree(data);
    34 }
    35 
    3630
    3731int main(int argc,
     
    5953        psVec->data.PTR[i] = ts;
    6054        psVec->n++;
    61         psMemIncrRefCounter(ts);
    6255    }
    6356
     
    8275        psVec->data.PTR[i] = ts;
    8376        psVec->n++;
    84         psMemIncrRefCounter(ts);
    8577    }
    8678    for(int i = 0; i < 10; i++) {
     
    9284    printFooter(stdout, "psVector", "Reallocate void pointer vector bigger", true);
    9385
    94 
    9586    // Test D - Reallocate void pointer vector smaller
    9687    printPositiveTestHeader(stdout,"psVector","Reallocate void pointer vector smaller");
    97     psVec = psVectorRealloc(3, psVec);
     88    psVec = psVectorRealloc(3, psVec); // this also frees the elements trimmed
    9889    for(int i = 0; i < 3; i++) {
    9990        testStruct *ts = (testStruct*)psVec->data.PTR[i];
     
    109100
    110101    // Free void pointer array struct and its 3 internal elements
    111     psVectorElementFree(psVec, freeData);
    112     psVectorFree(psVec);
     102    psFree(psVec);
    113103
    114     // Free 7 elements manually that were lost after array was reallocated smaller
    115     for(int i = 3; i < 10; i++) {
    116         psFree(mySt[i]);
     104    if (psMemCheckLeaks(0, NULL, stdout) != 0) {
     105        psAbort(__func__,"memory leaks");
    117106    }
    118     psMemCheckLeaks(0, NULL, stdout);
    119107    int nBad = psMemCheckCorruption(0);
    120108    if(nBad) {
Note: See TracChangeset for help on using the changeset viewer.