source: issm/oecreview/Archive/12321-12677/ISSM-12446-12447.diff@ 12679

Last change on this file since 12679 was 12679, checked in by Mathieu Morlighem, 13 years ago

Added 12321-12677

File size: 2.0 KB
  • TabularUnified u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/c/shared/Alloc/xNewDelete.h

     
    5858}
    5959
    6060template <class T>
    61 T* xReNew(T* old, unsigned int size) {
     61T* xReNew(T* old, unsigned int old_size, unsigned int size) {
    6262#ifdef USE_CXX_MEMORY_MANAGMENT_FOR_NON_POD_TYPES
    63   assert(old);
    64   T* aT_p=xNew<T>(size);
    65   for (unsigned int i=0; i<size;++i)
    66     aT_p[i]=old[i];
    67   xDelete<T>(old);
     63  T* aT_p=NULL;
     64  if (!old) { // no old memory
     65    if (size) 
     66      aT_p=xNew<T>(size);
     67  }
     68  else { // have old memory
     69    if (!size)  // but 0 size
     70      xDelete<T>(old);
     71    else { // non-zero size
     72      if (size>old_size) { // do something only if it is bigger
     73        aT_p=xNew<T>(size);
     74        for (unsigned int i=0; i<old_size;++i)
     75          aT_p[i]=old[i]; // copy the items
     76        xDelete<T>(old);
     77      }
     78      else // size is equal or less than old size
     79        aT_p=old; // do nothing
     80    }
     81  }
    6882  return aT_p;
    6983#else
    7084  T* aT_p=(T*)realloc((void*)old,size*sizeof(T));
  • TabularUnified u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/c/shared/TriMesh/TriMeshUtils.cpp

     
    6565                                }
    6666                                else{
    6767                                        /*Reallocate another max_number_elements slots in the GridElements: */
    68                                         GridElementsRealloc=xReNew<int>(GridElements,(current_size+max_number_elements));
     68                                        GridElementsRealloc=xReNew<int>(GridElements,current_size,(current_size+max_number_elements));
    6969                                        if (!GridElementsRealloc){
    7070                                                noerr=0;
    7171                                                goto cleanup_and_return;
Note: See TracBrowser for help on using the repository browser.