[Opentnl-cvs] tnl/tnl tnlVector.h,1.2,1.3
Brought to you by:
mark_frohnmayer,
s_alanet
From: Mark F. <mar...@us...> - 2004-05-06 01:36:09
|
Update of /cvsroot/opentnl/tnl/tnl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4906/tnl Modified Files: tnlVector.h Log Message: New Vector resizing scheme to fix reallocation bug in vector Rolled back Ben's sparkManager changes Index: tnlVector.h =================================================================== RCS file: /cvsroot/opentnl/tnl/tnl/tnlVector.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** tnlVector.h 3 May 2004 22:06:16 -0000 1.2 --- tnlVector.h 6 May 2004 01:36:01 -0000 1.3 *************** *** 310,313 **** --- 310,320 ---- destroy(size, oldSize); mElementCount = size; + + if(!mElementCount) + { + free(mArray); + mArray = NULL; + mArraySize = 0; + } return mElementCount; } *************** *** 413,417 **** template<class T> inline void Vector<T>::clear() { ! mElementCount = 0; } --- 420,424 ---- template<class T> inline void Vector<T>::clear() { ! setSize(0); } *************** *** 561,570 **** template<class T> inline bool Vector<T>::resize(U32 ecount) { ! #ifdef DEBUG_GUARD ! return VectorResize(&mArraySize, &mElementCount, (void**) &mArray, ecount, sizeof(T), ! mFileAssociation, mLineAssociation); ! #else ! return VectorResize(&mArraySize, &mElementCount, (void**) &mArray, ecount, sizeof(T)); ! #endif } --- 568,586 ---- template<class T> inline bool Vector<T>::resize(U32 ecount) { ! U32 blk = VectorBlockSize - (ecount % VectorBlockSize); ! U32 newCount = ecount + ((blk != VectorBlockSize) ? blk : 0); ! ! T *array = (T *) malloc(sizeof(T) * newCount); ! ! for(U32 i = 0; i < mElementCount; i++) ! { ! constructInPlace(&array[i], &mArray[i]); ! destructInPlace(&mArray[i]); ! } ! free(mArray); ! mArray = array; ! mArraySize = newCount; ! mElementCount = ecount; ! return true; } |