Changeset 4409 for trunk/psLib/src/collections/psVector.c
- Timestamp:
- Jun 28, 2005, 10:17:52 AM (21 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/collections/psVector.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/collections/psVector.c
r4392 r4409 9 9 * @author Robert DeSonia, MHPCC 10 10 * 11 * @version $Revision: 1.4 4$ $Name: not supported by cvs2svn $12 * @date $Date: 2005-06-2 5 02:02:05$11 * @version $Revision: 1.45 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2005-06-28 20:17:52 $ 13 13 * 14 14 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 48 48 // FUNCTION IMPLEMENTATION - PUBLIC 49 49 50 psVector* psVectorAlloc( psU32 nalloc, psElemType elemType)50 psVector* psVectorAlloc(unsigned long nalloc, psElemType type) 51 51 { 52 52 psVector* psVec = NULL; 53 53 psS32 elementSize = 0; 54 54 55 elementSize = PSELEMTYPE_SIZEOF( elemType);55 elementSize = PSELEMTYPE_SIZEOF(type); 56 56 if (elementSize < 1) { 57 57 psError(PS_ERR_BAD_PARAMETER_TYPE, true, 58 PS_ERRORTEXT_psVector_UNSUPPORTED_TYPE, elemType);58 PS_ERRORTEXT_psVector_UNSUPPORTED_TYPE, type); 59 59 return NULL; 60 60 } … … 66 66 67 67 psVec->type.dimen = PS_DIMEN_VECTOR; 68 psVec->type.type = elemType;68 psVec->type.type = type; 69 69 *(int*)&psVec->nalloc = nalloc; 70 70 psVec->n = nalloc; … … 76 76 } 77 77 78 psVector* psVectorRealloc(psVector* in, psU32nalloc)78 psVector* psVectorRealloc(psVector* vector, unsigned long nalloc) 79 79 { 80 80 psS32 elementSize = 0; 81 81 psElemType elemType; 82 82 83 if ( in== NULL) {83 if (vector == NULL) { 84 84 psError(PS_ERR_BAD_PARAMETER_NULL, true, 85 85 PS_ERRORTEXT_psVector_REALLOC_NULL); 86 86 return NULL; 87 } else if ( in->nalloc != nalloc) { // No need to realloc to same size88 elemType = in->type.type;87 } else if (vector->nalloc != nalloc) { // No need to realloc to same size 88 elemType = vector->type.type; 89 89 elementSize = PSELEMTYPE_SIZEOF(elemType); 90 if (nalloc < in->n) {91 in->n = nalloc;90 if (nalloc < vector->n) { 91 vector->n = nalloc; 92 92 } 93 93 // Realloc after decrementation to avoid accessing freed array elements 94 in->data.U8 = psRealloc(in->data.U8, nalloc * elementSize);95 *(int*)& in->nalloc = nalloc;96 } 97 98 return in;99 } 100 101 psVector* psVectorRecycle(psVector* in, psU32 n, psElemType type)94 vector->data.U8 = psRealloc(vector->data.U8, nalloc * elementSize); 95 *(int*)&vector->nalloc = nalloc; 96 } 97 98 return vector; 99 } 100 101 psVector* psVectorRecycle(psVector* vector, unsigned long nalloc, psElemType type) 102 102 { 103 103 psS32 byteSize; 104 104 105 if ( in== NULL) {106 return psVectorAlloc(n , type);107 } 108 109 if ( in->type.dimen != PS_DIMEN_VECTOR &&110 in->type.dimen != PS_DIMEN_TRANSV) {111 psFree( in);105 if (vector == NULL) { 106 return psVectorAlloc(nalloc, type); 107 } 108 109 if (vector->type.dimen != PS_DIMEN_VECTOR && 110 vector->type.dimen != PS_DIMEN_TRANSV) { 111 psFree(vector); 112 112 psError(PS_ERR_BAD_PARAMETER_TYPE, true, 113 113 PS_ERRORTEXT_psVector_NOT_A_VECTOR); … … 115 115 } 116 116 117 byteSize = n * PSELEMTYPE_SIZEOF(type);117 byteSize = nalloc * PSELEMTYPE_SIZEOF(type); 118 118 119 119 // need to increase data buffer? 120 if (byteSize > in->nalloc*PSELEMTYPE_SIZEOF(in->type.type)) {121 in->data.U8 = psRealloc(in->data.U8, byteSize);122 *(int*)& in->nalloc = n;123 } 124 125 in->type.dimen = PS_DIMEN_VECTOR;126 in->type.type = type;127 in->n = n;128 return in;120 if (byteSize > vector->nalloc*PSELEMTYPE_SIZEOF(vector->type.type)) { 121 vector->data.U8 = psRealloc(vector->data.U8, byteSize); 122 *(int*)&vector->nalloc = nalloc; 123 } 124 125 vector->type.dimen = PS_DIMEN_VECTOR; 126 vector->type.type = type; 127 vector->n = nalloc; 128 return vector; 129 129 } 130 130
Note:
See TracChangeset
for help on using the changeset viewer.
