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
RevLine 
[12679]1Index: /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));
39Index: /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;
Note: See TracBrowser for help on using the repository browser.