Changeset 811
- Timestamp:
- May 28, 2004, 3:08:46 PM (22 years ago)
- Location:
- trunk/psLib/src
- Files:
-
- 4 edited
-
collections/psVector.c (modified) (3 diffs)
-
collections/psVector.h (modified) (2 diffs)
-
mathtypes/psVector.c (modified) (3 diffs)
-
mathtypes/psVector.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/collections/psVector.c
r689 r811 19 19 * @author Ross Harman, MHPCC 20 20 * 21 * @version $Revision: 1. 5$ $Name: not supported by cvs2svn $22 * @date $Date: 2004-05- 14 21:05:52$21 * @version $Revision: 1.6 $ $Name: not supported by cvs2svn $ 22 * @date $Date: 2004-05-29 01:08:46 $ 23 23 * 24 24 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 91 91 } 92 92 93 psVector *psVectorRealloc(psVector *restrict psVec, unsigned int nalloc)93 psVector *psVectorRealloc(psVector *restrict in, unsigned int nalloc) 94 94 { 95 95 int elementSize = 0; 96 psElemType elemType = psVec->type.type;96 psElemType elemType; 97 97 98 98 // Invalid nalloc … … 102 102 } 103 103 104 elementSize = PSELEMTYPE_SIZEOF(elemType);105 106 if(psVec == NULL) { // For creating new psVector107 psVec = psVectorAlloc(psVec->type.type, nalloc);108 } else if(psVec->nalloc != nalloc) { // No need to realloc to same size109 if(nalloc < psVec->n) {104 if(in == NULL) { // For creating new psVector 105 return NULL; 106 } else if(in->nalloc != nalloc) { // No need to realloc to same size 107 elemType = in->type.type; 108 elementSize = PSELEMTYPE_SIZEOF(elemType); 109 if(nalloc < in->n) { 110 110 if (elemType == PS_TYPE_PTR) { 111 for (int i = nalloc; i < psVec->n; i++) { // For reduction in vector size112 psMemDecrRefCounter( psVec->vec.vp[i]);111 for (int i = nalloc; i < in->n; i++) { // For reduction in vector size 112 psMemDecrRefCounter(in->vec.vp[i]); 113 113 } 114 114 } 115 psVec->n = nalloc;115 in->n = nalloc; 116 116 } 117 117 118 118 // Realloc after decrementation to avoid accessing freed array elements 119 psVec->vec.v = psRealloc(psVec->vec.v,nalloc*elementSize);120 psVec->nalloc = nalloc;119 in->vec.v = psRealloc(in->vec.v,nalloc*elementSize); 120 in->nalloc = nalloc; 121 121 } 122 122 123 return psVec; 123 return in; 124 } 125 126 psVector *psVectorRecycle(psVector *restrict in, psElemType type, unsigned int nalloc) 127 { 128 psElemType elemType; 129 130 if (in == NULL) { 131 return psVectorAlloc(type,nalloc); 132 } 133 134 elemType = in->type.type; 135 136 if (in->nalloc == nalloc && elemType == type) { 137 // it is proper size/type already 138 return in; 139 } 140 141 // Invalid nalloc 142 if(nalloc < 1) { 143 psError(__func__, "Invalid value for nalloc (%d)\n", nalloc); 144 psVectorFree(in); 145 return NULL; 146 } 147 148 149 // if vector of pointers, dereference old values. 150 if (elemType == PS_TYPE_PTR) { 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; 154 } 155 } 156 157 in->vec.v = psRealloc(in->vec.v,nalloc*PSELEMTYPE_SIZEOF(elemType)); 158 159 in->n = 0; 160 in->type.type = elemType; 161 in->nalloc = nalloc; 162 163 return in; 124 164 } 125 165 -
trunk/psLib/src/collections/psVector.h
r672 r811 19 19 * @author Ross Harman, MHPCC 20 20 * 21 * @version $Revision: 1. 6$ $Name: not supported by cvs2svn $22 * @date $Date: 2004-05- 13 23:36:27$21 * @version $Revision: 1.7 $ $Name: not supported by cvs2svn $ 22 * @date $Date: 2004-05-29 01:08:46 $ 23 23 * 24 24 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 88 88 ); 89 89 90 /** Recycle a vector. 91 * 92 * Uses psLib memory allocation functions to reallocate a vector collection of data. The vector is reallocated 93 * according to the psElemType type parameter. 94 * 95 * @return psVector*: Pointer to psVector. 96 * 97 */ 98 psVector *psVectorRecycle( 99 psVector *restrict psVec, 100 ///< Vector to recycle. If NULL, a new vector is created. No effort taken to preserve the values. 101 102 unsigned int nalloc, ///< Total number of elements to make available. 103 psElemType type ///< the datatype of the returned vector 104 ); 105 90 106 /** Deallocate a vector. 91 107 * -
trunk/psLib/src/mathtypes/psVector.c
r689 r811 19 19 * @author Ross Harman, MHPCC 20 20 * 21 * @version $Revision: 1. 5$ $Name: not supported by cvs2svn $22 * @date $Date: 2004-05- 14 21:05:52$21 * @version $Revision: 1.6 $ $Name: not supported by cvs2svn $ 22 * @date $Date: 2004-05-29 01:08:46 $ 23 23 * 24 24 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 91 91 } 92 92 93 psVector *psVectorRealloc(psVector *restrict psVec, unsigned int nalloc)93 psVector *psVectorRealloc(psVector *restrict in, unsigned int nalloc) 94 94 { 95 95 int elementSize = 0; 96 psElemType elemType = psVec->type.type;96 psElemType elemType; 97 97 98 98 // Invalid nalloc … … 102 102 } 103 103 104 elementSize = PSELEMTYPE_SIZEOF(elemType);105 106 if(psVec == NULL) { // For creating new psVector107 psVec = psVectorAlloc(psVec->type.type, nalloc);108 } else if(psVec->nalloc != nalloc) { // No need to realloc to same size109 if(nalloc < psVec->n) {104 if(in == NULL) { // For creating new psVector 105 return NULL; 106 } else if(in->nalloc != nalloc) { // No need to realloc to same size 107 elemType = in->type.type; 108 elementSize = PSELEMTYPE_SIZEOF(elemType); 109 if(nalloc < in->n) { 110 110 if (elemType == PS_TYPE_PTR) { 111 for (int i = nalloc; i < psVec->n; i++) { // For reduction in vector size112 psMemDecrRefCounter( psVec->vec.vp[i]);111 for (int i = nalloc; i < in->n; i++) { // For reduction in vector size 112 psMemDecrRefCounter(in->vec.vp[i]); 113 113 } 114 114 } 115 psVec->n = nalloc;115 in->n = nalloc; 116 116 } 117 117 118 118 // Realloc after decrementation to avoid accessing freed array elements 119 psVec->vec.v = psRealloc(psVec->vec.v,nalloc*elementSize);120 psVec->nalloc = nalloc;119 in->vec.v = psRealloc(in->vec.v,nalloc*elementSize); 120 in->nalloc = nalloc; 121 121 } 122 122 123 return psVec; 123 return in; 124 } 125 126 psVector *psVectorRecycle(psVector *restrict in, psElemType type, unsigned int nalloc) 127 { 128 psElemType elemType; 129 130 if (in == NULL) { 131 return psVectorAlloc(type,nalloc); 132 } 133 134 elemType = in->type.type; 135 136 if (in->nalloc == nalloc && elemType == type) { 137 // it is proper size/type already 138 return in; 139 } 140 141 // Invalid nalloc 142 if(nalloc < 1) { 143 psError(__func__, "Invalid value for nalloc (%d)\n", nalloc); 144 psVectorFree(in); 145 return NULL; 146 } 147 148 149 // if vector of pointers, dereference old values. 150 if (elemType == PS_TYPE_PTR) { 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; 154 } 155 } 156 157 in->vec.v = psRealloc(in->vec.v,nalloc*PSELEMTYPE_SIZEOF(elemType)); 158 159 in->n = 0; 160 in->type.type = elemType; 161 in->nalloc = nalloc; 162 163 return in; 124 164 } 125 165 -
trunk/psLib/src/mathtypes/psVector.h
r672 r811 19 19 * @author Ross Harman, MHPCC 20 20 * 21 * @version $Revision: 1. 6$ $Name: not supported by cvs2svn $22 * @date $Date: 2004-05- 13 23:36:27$21 * @version $Revision: 1.7 $ $Name: not supported by cvs2svn $ 22 * @date $Date: 2004-05-29 01:08:46 $ 23 23 * 24 24 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 88 88 ); 89 89 90 /** Recycle a vector. 91 * 92 * Uses psLib memory allocation functions to reallocate a vector collection of data. The vector is reallocated 93 * according to the psElemType type parameter. 94 * 95 * @return psVector*: Pointer to psVector. 96 * 97 */ 98 psVector *psVectorRecycle( 99 psVector *restrict psVec, 100 ///< Vector to recycle. If NULL, a new vector is created. No effort taken to preserve the values. 101 102 unsigned int nalloc, ///< Total number of elements to make available. 103 psElemType type ///< the datatype of the returned vector 104 ); 105 90 106 /** Deallocate a vector. 91 107 *
Note:
See TracChangeset
for help on using the changeset viewer.
