Index: /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/c/shared/Alloc/xNewDelete.h =================================================================== --- /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/c/shared/Alloc/xNewDelete.h (revision 12446) +++ /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/c/shared/Alloc/xNewDelete.h (revision 12447) @@ -58,13 +58,27 @@ } template -T* xReNew(T* old, unsigned int size) { +T* xReNew(T* old, unsigned int old_size, unsigned int size) { #ifdef USE_CXX_MEMORY_MANAGMENT_FOR_NON_POD_TYPES - assert(old); - T* aT_p=xNew(size); - for (unsigned int i=0; i(old); + T* aT_p=NULL; + if (!old) { // no old memory + if (size) + aT_p=xNew(size); + } + else { // have old memory + if (!size) // but 0 size + xDelete(old); + else { // non-zero size + if (size>old_size) { // do something only if it is bigger + aT_p=xNew(size); + for (unsigned int i=0; i(old); + } + else // size is equal or less than old size + aT_p=old; // do nothing + } + } return aT_p; #else T* aT_p=(T*)realloc((void*)old,size*sizeof(T)); Index: /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/c/shared/TriMesh/TriMeshUtils.cpp =================================================================== --- /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/c/shared/TriMesh/TriMeshUtils.cpp (revision 12446) +++ /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/c/shared/TriMesh/TriMeshUtils.cpp (revision 12447) @@ -65,7 +65,7 @@ } else{ /*Reallocate another max_number_elements slots in the GridElements: */ - GridElementsRealloc=xReNew(GridElements,(current_size+max_number_elements)); + GridElementsRealloc=xReNew(GridElements,current_size,(current_size+max_number_elements)); if (!GridElementsRealloc){ noerr=0; goto cleanup_and_return;