IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 24, 2006, 12:55:05 PM (20 years ago)
Author:
Paul Price
Message:

Following today's meeting, we agreed that psVectorAlloc (and therefore
psArrayAlloc also) shall set the number of elements in use to equal the
number of elements allocated. We introduce new functions,
psVectorAllocEmpty and psArrayAllocEmpty, that allocate a vector and set
the length to zero.

Location:
trunk/psLib/src/mathtypes
Files:
2 edited

Legend:

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

    r9554 r9730  
    99*  @author Robert DeSonia, MHPCC
    1010*
    11 *  @version $Revision: 1.86 $ $Name: not supported by cvs2svn $
    12 *  @date $Date: 2006-10-14 00:12:39 $
     11*  @version $Revision: 1.87 $ $Name: not supported by cvs2svn $
     12*  @date $Date: 2006-10-24 22:52:56 $
    1313*
    1414*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    6868
    6969
    70 psVector* psVectorAlloc(long nalloc,
    71                         psElemType type)
    72 {
    73     psVector* psVec = NULL;
    74     psS32 elementSize = 0;
    75 
    76     elementSize = PSELEMTYPE_SIZEOF(type);
     70// Allocate a psVector; does not set vector->n (left to the caller)
     71static psVector *vectorAlloc(long nalloc, // Number of elements to allocate
     72                             psElemType type // Type of elements
     73                            )
     74{
     75    int elementSize = PSELEMTYPE_SIZEOF(type); // Size, in bytes, of element
    7776    if (elementSize < 1) {
    7877        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
     
    8180    }
    8281
    83 
    8482    // Create vector struct
    85     psVec = (psVector* ) psAlloc(sizeof(psVector));
    86     psMemSetDeallocator(psVec, (psFreeFunc) vectorFree);
    87 
    88     psVec->type.dimen = PS_DIMEN_VECTOR;
    89     psVec->type.type = type;
    90     P_PSVECTOR_SET_NALLOC(psVec,nalloc);
    91     //    psVec->n = nalloc;
    92     psVec->n = 0;
     83    psVector *vector = (psVector*) psAlloc(sizeof(psVector));
     84    psMemSetDeallocator(vector, (psFreeFunc) vectorFree);
     85
     86    vector->type.dimen = PS_DIMEN_VECTOR;
     87    vector->type.type = type;
     88    P_PSVECTOR_SET_NALLOC(vector, nalloc);
    9389
    9490    // Create vector data array
    95     psVec->data.U8 = psAlloc(nalloc * elementSize);
    96 
    97     return psVec;
     91    vector->data.U8 = psAlloc(nalloc * elementSize);
     92
     93    return vector;
     94}
     95
     96psVector* psVectorAlloc(long nalloc,
     97                        psElemType type)
     98{
     99    psVector *vector = vectorAlloc(nalloc, type);
     100    if (!vector) {
     101        return NULL;
     102    }
     103    vector->n = nalloc;
     104    return vector;
     105}
     106
     107psVector* psVectorAllocEmpty(long nalloc,
     108                             psElemType type)
     109{
     110    psVector *vector = vectorAlloc(nalloc, type);
     111    if (!vector) {
     112        return NULL;
     113    }
     114    vector->n = 0;
     115    return vector;
    98116}
    99117
  • trunk/psLib/src/mathtypes/psVector.h

    r9553 r9730  
    1111 *  @author Ross Harman, MHPCC
    1212 *
    13  *  @version $Revision: 1.58 $ $Name: not supported by cvs2svn $
    14  *  @date $Date: 2006-10-14 00:07:13 $
     13 *  @version $Revision: 1.59 $ $Name: not supported by cvs2svn $
     14 *  @date $Date: 2006-10-24 22:52:56 $
    1515 *
    1616 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    7474        ;
    7575
    76 /** Allocate a vector.
     76/** Allocate a vector, with length set to number allocated
    7777 *
    7878 *  Uses psLib memory allocation functions to create a vector collection of
     
    8282 */
    8383psVector* psVectorAlloc(
     84    long nalloc,                       ///< Total number of elements to make available.
     85    psElemType type                    ///< Type of data to be held by vector.
     86);
     87
     88/** Allocate a vector, with length set to zero
     89 *
     90 *  Uses psLib memory allocation functions to create a vector collection of
     91 *  data as defined by the psType type.
     92 *
     93 * @return psVector*    Pointer to psVector.
     94 */
     95psVector* psVectorAllocEmpty(
    8496    long nalloc,                       ///< Total number of elements to make available.
    8597    psElemType type                    ///< Type of data to be held by vector.
Note: See TracChangeset for help on using the changeset viewer.