[12679] | 1 | Index: /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/c/shared/Alloc/xNewDelete.h
|
---|
| 2 | ===================================================================
|
---|
| 3 | --- /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/c/shared/Alloc/xNewDelete.h (revision 12446)
|
---|
| 4 | +++ /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/c/shared/Alloc/xNewDelete.h (revision 12447)
|
---|
| 5 | @@ -58,13 +58,27 @@
|
---|
| 6 | }
|
---|
| 7 |
|
---|
| 8 | template <class T>
|
---|
| 9 | -T* xReNew(T* old, unsigned int size) {
|
---|
| 10 | +T* xReNew(T* old, unsigned int old_size, unsigned int size) {
|
---|
| 11 | #ifdef USE_CXX_MEMORY_MANAGMENT_FOR_NON_POD_TYPES
|
---|
| 12 | - assert(old);
|
---|
| 13 | - T* aT_p=xNew<T>(size);
|
---|
| 14 | - for (unsigned int i=0; i<size;++i)
|
---|
| 15 | - aT_p[i]=old[i];
|
---|
| 16 | - xDelete<T>(old);
|
---|
| 17 | + T* aT_p=NULL;
|
---|
| 18 | + if (!old) { // no old memory
|
---|
| 19 | + if (size)
|
---|
| 20 | + aT_p=xNew<T>(size);
|
---|
| 21 | + }
|
---|
| 22 | + else { // have old memory
|
---|
| 23 | + if (!size) // but 0 size
|
---|
| 24 | + xDelete<T>(old);
|
---|
| 25 | + else { // non-zero size
|
---|
| 26 | + if (size>old_size) { // do something only if it is bigger
|
---|
| 27 | + aT_p=xNew<T>(size);
|
---|
| 28 | + for (unsigned int i=0; i<old_size;++i)
|
---|
| 29 | + aT_p[i]=old[i]; // copy the items
|
---|
| 30 | + xDelete<T>(old);
|
---|
| 31 | + }
|
---|
| 32 | + else // size is equal or less than old size
|
---|
| 33 | + aT_p=old; // do nothing
|
---|
| 34 | + }
|
---|
| 35 | + }
|
---|
| 36 | return aT_p;
|
---|
| 37 | #else
|
---|
| 38 | T* aT_p=(T*)realloc((void*)old,size*sizeof(T));
|
---|
| 39 | Index: /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/c/shared/TriMesh/TriMeshUtils.cpp
|
---|
| 40 | ===================================================================
|
---|
| 41 | --- /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/c/shared/TriMesh/TriMeshUtils.cpp (revision 12446)
|
---|
| 42 | +++ /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/c/shared/TriMesh/TriMeshUtils.cpp (revision 12447)
|
---|
| 43 | @@ -65,7 +65,7 @@
|
---|
| 44 | }
|
---|
| 45 | else{
|
---|
| 46 | /*Reallocate another max_number_elements slots in the GridElements: */
|
---|
| 47 | - GridElementsRealloc=xReNew<int>(GridElements,(current_size+max_number_elements));
|
---|
| 48 | + GridElementsRealloc=xReNew<int>(GridElements,current_size,(current_size+max_number_elements));
|
---|
| 49 | if (!GridElementsRealloc){
|
---|
| 50 | noerr=0;
|
---|
| 51 | goto cleanup_and_return;
|
---|