Changeset 11701
- Timestamp:
- Feb 7, 2007, 5:34:09 PM (19 years ago)
- Location:
- trunk/psLib/src/types
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/types/psArray.c
r10999 r11701 9 9 * @author Ross Harman, MHPCC 10 10 * 11 * @version $Revision: 1.5 8$ $Name: not supported by cvs2svn $12 * @date $Date: 2007-0 1-09 22:38:53$11 * @version $Revision: 1.59 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2007-02-08 03:34:09 $ 13 13 * 14 14 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 54 54 55 55 // Allocate an array, deliberately leave size unset. 56 static psArray *arrayAlloc(long nalloc) 56 static psArray *arrayAlloc(const char *file, 57 unsigned int lineno, 58 const char *func, 59 long nalloc) 57 60 { 58 61 if (nalloc < 0) { … … 77 80 FUNCTION IMPLEMENTATION - PUBLIC 78 81 *****************************************************************************/ 79 psArray* psArrayAlloc(long nalloc) 80 { 81 psArray *array = arrayAlloc(nalloc); 82 psArray* p_psArrayAlloc(const char *file, 83 unsigned int lineno, 84 const char *func, 85 long nalloc) 86 { 87 psArray *array = arrayAlloc(file, lineno, func, nalloc); 82 88 if (!array) { 83 89 return NULL; … … 87 93 } 88 94 89 psArray* psArrayAllocEmpty(long nalloc) 90 { 91 psArray *array = arrayAlloc(nalloc); 95 psArray* p_psArrayAllocEmpty(const char *file, 96 unsigned int lineno, 97 const char *func, 98 long nalloc) 99 { 100 psArray *array = arrayAlloc(file, lineno, func, nalloc); 92 101 if (!array) { 93 102 return NULL; … … 97 106 } 98 107 99 psArray* psArrayRealloc(psArray* in, 100 long nalloc) 108 psArray* p_psArrayRealloc(const char *file, 109 unsigned int lineno, 110 const char *func, 111 psArray* in, 112 long nalloc) 101 113 { 102 114 if (nalloc < 0) { … … 118 130 // Realloc after decrementation to avoid accessing freed array elements 119 131 long n = in->n; 120 in->data = p sRealloc(in->data, nalloc * sizeof(psPtr));132 in->data = p_psRealloc(file, lineno, func, in->data, nalloc * sizeof(psPtr)); 121 133 P_PSARRAY_SET_NALLOC(in,nalloc); 122 134 for (long m = n; m < nalloc; m++) { //if array is grown, set grown data to NULL -
trunk/psLib/src/types/psArray.h
r11668 r11701 8 8 * @author Robert DeSonia, MHPCC 9 9 * @author Ross Harman, MHPCC 10 * 11 * @version $Revision: 1.46 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2007-02-06 21:36:09 $ 10 * @author Joshua Hoblitt, University of Hawaii 11 * 12 * @version $Revision: 1.47 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2007-02-08 03:34:09 $ 13 14 * 14 15 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 40 41 #define P_PSARRAY_SET_NALLOC(vec,n) *(long*)&vec->nalloc = n 41 42 42 /*****************************************************************************/ 43 44 /* FUNCTION PROTOTYPES */ 45 46 /*****************************************************************************/ 47 48 /** Checks the type of a particular pointer. 49 * 50 * Uses the appropriate deallocation function in psMemBlock to check the ptr datatype. 51 * 52 * @return bool: True if the pointer matches a psArray structure, false otherwise. 53 */ 54 bool psMemCheckArray( 55 psPtr ptr ///< the pointer whose type to check 56 ) 57 ; 43 /*****************************************************************************/ 44 45 /* FUNCTION PROTOTYPES */ 46 47 /*****************************************************************************/ 48 49 /** Checks the type of a particular pointer. 50 * 51 * Uses the appropriate deallocation function in psMemBlock to check the ptr 52 * datatype. 53 * 54 * @return bool: True if the pointer matches a psArray structure, false 55 * otherwise. 56 */ 57 bool psMemCheckArray( 58 psPtr ptr ///< the pointer whose type to check 59 ) 60 ; 58 61 59 62 … … 66 69 * 67 70 */ 71 #ifdef DOXYGEN 68 72 psArray* psArrayAlloc( 69 long nalloc ///< Total number of elements to make available. 70 ); 73 long nalloc ///< Total number of elements to make available. 74 ); 75 #else // ifdef DOXYGEN 76 psArray* p_psArrayAlloc( 77 const char *file, ///< File of caller 78 unsigned int lineno, ///< Line number of caller 79 const char *func, ///< Function name of caller 80 long nalloc ///< Total number of elements to make available. 81 ); 82 #define psArrayAlloc(nalloc) \ 83 p_psArrayAlloc(__FILE__, __LINE__, __func__, nalloc) 84 #endif // ifdef DOXYGEN 85 71 86 72 87 /** Allocate an array, set the length to zero. … … 78 93 * 79 94 */ 95 #ifdef DOXYGEN 80 96 psArray* psArrayAllocEmpty( 81 long nalloc ///< Total number of elements to make available. 82 ); 97 long nalloc ///< Total number of elements to make available. 98 ); 99 #else // ifdef DOXYGEN 100 psArray* p_psArrayAllocEmpty( 101 const char *file, ///< File of caller 102 unsigned int lineno, ///< Line number of caller 103 const char *func, ///< Function name of caller 104 long nalloc ///< Total number of elements to make available. 105 ); 106 #define psArrayAllocEmpty(nalloc) \ 107 p_psArrayAllocEmpty(__FILE__, __LINE__, __func__, nalloc) 108 #endif // ifdef DOXYGEN 109 83 110 84 111 /** Reallocate an array. … … 90 117 * 91 118 */ 119 #ifdef DOXYGEN 92 120 psArray* psArrayRealloc( 93 121 psArray* array, ///< array to reallocate. 94 122 long nalloc ///< Total number of elements to make available. 95 123 ); 124 #else // ifdef DOXYGEN 125 psArray* p_psArrayRealloc( 126 const char *file, ///< File of caller 127 unsigned int lineno, ///< Line number of caller 128 const char *func, ///< Function name of caller 129 psArray* array, ///< array to reallocate. 130 long nalloc ///< Total number of elements to make available. 131 ); 132 #define psArrayRealloc(array, nalloc) \ 133 p_psArrayRealloc(__FILE__, __LINE__, __func__, array, nalloc) 134 #endif // ifdef DOXYGEN 135 96 136 97 137 /** Add an element to the end the array, expanding the array storage if … … 102 142 psArray* psArrayAdd( 103 143 psArray* array, ///< array to operate on 104 long delta, 105 ///< the amount to expand array, if necessary. If less than one, 10 will be used. 144 long delta, ///< the amount to expand array, if necessary. If less than one, 10 will be used. 106 145 psPtr data ///< the data pointer to add to psArray 107 146 ); 147 108 148 109 149 /** Remove an element from the array by it's pointer … … 120 160 ); 121 161 162 122 163 /** Remove an element from the array 123 164 * … … 133 174 ); 134 175 176 135 177 /** Deallocate/Dereference elements of an array. 136 178 * … … 144 186 ); 145 187 188 146 189 /** Sort the array according to an external compare function. 147 190 * … … 162 205 psComparePtrFunc func ///< the compare function 163 206 ); 207 164 208 165 209 /** Set an element in the array. If the current element is non-NULL, the old … … 174 218 ); 175 219 220 176 221 /** Get an element from the array. 177 222 * … … 182 227 long position ///< the element position to get 183 228 ); 229 184 230 185 231 /** Get the number of elements in use from a specified psArray. (array.n)
Note:
See TracChangeset
for help on using the changeset viewer.
