Changeset 831 for trunk/psLib/src/collections/psVector.c
- Timestamp:
- Jun 2, 2004, 1:29:39 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/collections/psVector.c (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/collections/psVector.c
r811 r831 19 19 * @author Ross Harman, MHPCC 20 20 * 21 * @version $Revision: 1. 6$ $Name: not supported by cvs2svn $22 * @date $Date: 2004-0 5-29 01:08:46$21 * @version $Revision: 1.7 $ $Name: not supported by cvs2svn $ 22 * @date $Date: 2004-06-02 23:29:14 $ 23 23 * 24 24 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 64 64 /* FUNCTION IMPLEMENTATION - PUBLIC */ 65 65 /*****************************************************************************/ 66 psVector* psVectorAlloc( psElemType elemType, unsigned int nalloc)66 psVector* psVectorAlloc(unsigned int nalloc, psElemType elemType) 67 67 { 68 68 psVector *psVec = NULL; … … 86 86 87 87 // Create vector data array 88 psVec-> vec.v= psAlloc(nalloc*elementSize);88 psVec->data.V = psAlloc(nalloc*elementSize); 89 89 90 90 return psVec; 91 91 } 92 92 93 psVector *psVectorRealloc( psVector *restrict in, unsigned int nalloc)93 psVector *psVectorRealloc(unsigned int nalloc, psVector *restrict in) 94 94 { 95 95 int elementSize = 0; … … 110 110 if (elemType == PS_TYPE_PTR) { 111 111 for (int i = nalloc; i < in->n; i++) { // For reduction in vector size 112 psMemDecrRefCounter(in-> vec.vp[i]);112 psMemDecrRefCounter(in->data.PTR[i]); 113 113 } 114 114 } … … 117 117 118 118 // Realloc after decrementation to avoid accessing freed array elements 119 in-> vec.v = psRealloc(in->vec.v,nalloc*elementSize);119 in->data.V = psRealloc(in->data.V,nalloc*elementSize); 120 120 in->nalloc = nalloc; 121 121 } … … 129 129 130 130 if (in == NULL) { 131 return psVectorAlloc( type,nalloc);131 return psVectorAlloc(nalloc, type); 132 132 } 133 133 … … 150 150 if (elemType == PS_TYPE_PTR) { 151 151 for (int i = 0; i < in->n; i++) { // For reduction in vector size 152 psMemDecrRefCounter(in-> vec.vp[i]);153 in-> vec.vp[i] = NULL;152 psMemDecrRefCounter(in->data.PTR[i]); 153 in->data.PTR[i] = NULL; 154 154 } 155 155 } 156 156 157 in-> vec.v = psRealloc(in->vec.v,nalloc*PSELEMTYPE_SIZEOF(elemType));157 in->data.V = psRealloc(in->data.V,nalloc*PSELEMTYPE_SIZEOF(elemType)); 158 158 159 159 in->n = 0; … … 170 170 } 171 171 172 psFree(psVec-> vec.v);172 psFree(psVec->data.V); 173 173 psFree(psVec); 174 174 } … … 188 188 for(int i = 0; i < psVec->nalloc; i++) { 189 189 if(elemFree == NULL) { 190 psMemDecrRefCounter(psVec-> vec.vp[i]);190 psMemDecrRefCounter(psVec->data.PTR[i]); 191 191 } else { 192 elemFree(psMemDecrRefCounter(psVec-> vec.vp[i]));192 elemFree(psMemDecrRefCounter(psVec->data.PTR[i])); 193 193 } 194 psVec-> vec.vp[i] = NULL;194 psVec->data.PTR[i] = NULL; 195 195 } 196 196 }
Note:
See TracChangeset
for help on using the changeset viewer.
