IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 1820


Ignore:
Timestamp:
Sep 16, 2004, 1:47:43 PM (22 years ago)
Author:
desonia
Message:

adjusted psVectorRecycle to avoid a realloc if data buffer is bigger than needed. nalloc is, in that case, not reset, but the number of elements, n, is set to the requested amount.

Location:
trunk/psLib/src
Files:
2 edited

Legend:

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

    r1807 r1820  
    1010*  @author Robert DeSonia, MHPCC
    1111*
    12 *  @version $Revision: 1.24 $ $Name: not supported by cvs2svn $
    13 *  @date $Date: 2004-09-14 20:01:52 $
     12*  @version $Revision: 1.25 $ $Name: not supported by cvs2svn $
     13*  @date $Date: 2004-09-16 23:47:43 $
    1414*
    1515*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    8888}
    8989
    90 psVector* psVectorRecycle(psVector* restrict in, unsigned int nalloc, psElemType type)
    91 {
    92     psElemType elemType;
     90psVector* psVectorRecycle(psVector* restrict in, unsigned int n, psElemType type)
     91{
     92    int byteSize;
    9393
    9494    if (in == NULL) {
    95         return psVectorAlloc(nalloc, type);
    96     }
    97 
    98     elemType = in->type.type;
    99 
    100     if (in->nalloc == nalloc && elemType == type) {
    101         // it is proper size/type already
    102         return in;
    103     }
    104 
    105     in->data.V = psRealloc(in->data.V, nalloc * PSELEMTYPE_SIZEOF(type));
     95        return psVectorAlloc(n, type);
     96    }
     97
     98    byteSize = n * PSELEMTYPE_SIZEOF(type);
     99
     100    // need to increase data buffer?
     101    if (byteSize > in->nalloc*PSELEMTYPE_SIZEOF(in->type.type)) {
     102        in->data.V = psRealloc(in->data.V, byteSize);
     103        in->nalloc = n;
     104    }
    106105
    107106    in->type.type = type;
    108     in->nalloc = nalloc;
    109     in->n = nalloc;
     107    in->n = n;
    110108
    111109    return in;
  • trunk/psLib/src/mathtypes/psVector.c

    r1807 r1820  
    1010*  @author Robert DeSonia, MHPCC
    1111*
    12 *  @version $Revision: 1.24 $ $Name: not supported by cvs2svn $
    13 *  @date $Date: 2004-09-14 20:01:52 $
     12*  @version $Revision: 1.25 $ $Name: not supported by cvs2svn $
     13*  @date $Date: 2004-09-16 23:47:43 $
    1414*
    1515*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    8888}
    8989
    90 psVector* psVectorRecycle(psVector* restrict in, unsigned int nalloc, psElemType type)
    91 {
    92     psElemType elemType;
     90psVector* psVectorRecycle(psVector* restrict in, unsigned int n, psElemType type)
     91{
     92    int byteSize;
    9393
    9494    if (in == NULL) {
    95         return psVectorAlloc(nalloc, type);
    96     }
    97 
    98     elemType = in->type.type;
    99 
    100     if (in->nalloc == nalloc && elemType == type) {
    101         // it is proper size/type already
    102         return in;
    103     }
    104 
    105     in->data.V = psRealloc(in->data.V, nalloc * PSELEMTYPE_SIZEOF(type));
     95        return psVectorAlloc(n, type);
     96    }
     97
     98    byteSize = n * PSELEMTYPE_SIZEOF(type);
     99
     100    // need to increase data buffer?
     101    if (byteSize > in->nalloc*PSELEMTYPE_SIZEOF(in->type.type)) {
     102        in->data.V = psRealloc(in->data.V, byteSize);
     103        in->nalloc = n;
     104    }
    106105
    107106    in->type.type = type;
    108     in->nalloc = nalloc;
    109     in->n = nalloc;
     107    in->n = n;
    110108
    111109    return in;
Note: See TracChangeset for help on using the changeset viewer.