Example #1
0
 static void realloc(T ***ptr, Int old_num, Int new_num, 
                     const char *eyec="AzPMemTools::realloc", 
                     const char *errmsg="") 
 {
   check_overflow(new_num, eyec, errmsg); 
   T **new_ptr = NULL;  
   if (new_num > 0) {
     try {
       new_ptr = new T *[new_num]; 
     }
     catch (std::bad_alloc &ba) {
       throw new AzException(AzAllocError, eyec, errmsg, ba.what()); 
     }
     if (new_ptr == NULL) throw new AzException(AzAllocError, eyec, errmsg); 
     Int cpy_num = myMIN(old_num, new_num); 
     Int ix; 
     for (ix = 0; ix < cpy_num; ++ix) { 
       *(new_ptr + ix) = *(*ptr + ix); 
       *(*ptr + ix) = NULL;     
     }
     for ( ; ix < new_num; ++ix) *(new_ptr + ix) = NULL; 
   }
   free(ptr, old_num); 
   *ptr = new_ptr;  
 }
Example #2
0
 static void realloc_obj(T **ptr, Int old_num, Int new_num, 
                         const char *eyec="AzMemTools::realloc_obj", 
                         const char *errmsg="") {
   check_overflow(new_num, eyec, errmsg); 
   T *new_ptr = NULL;  
   if (new_num > 0) {
     try {
       new_ptr = new T[new_num]; 
     }
     catch (std::bad_alloc &ba) {
       throw new AzException(AzAllocError, eyec, errmsg, ba.what()); 
     }
     if (new_ptr == NULL) throw new AzException(AzAllocError, eyec, errmsg); 
     Int cpy_num = myMIN(old_num, new_num); 
     if (cpy_num > 0 && *ptr != NULL) {        
       Int ix; 
       try {
         for (ix = 0; ix < cpy_num; ++ix) new_ptr[ix].transfer_from(&((*ptr)[ix])); 
       }
       catch (AzException *e) {
         delete [] new_ptr; 
         throw e; 
       }
     }
   }
   delete [] *ptr;   
   *ptr = new_ptr;  
 }
Example #3
0
 static void realloc_base(T **ptr, int old_num, int new_num, 
                          const char *eyec="AzMemTools::realloc_base", 
                          const char *errmsg="") {
   T *new_ptr = NULL;  
   if (new_num > 0) {
     try {
       new_ptr = new T[new_num]; 
     }
     catch (std::bad_alloc &ba) {
       throw new AzException(AzAllocError, eyec, errmsg, ba.what()); 
     }
     if (new_ptr == NULL) throw new AzException(AzAllocError, eyec, errmsg); 
     int cpy_num = myMIN(old_num, new_num); 
     if (cpy_num > 0 && *ptr != NULL) {
       int ix; 
       for (ix = 0; ix < cpy_num; ++ix) {
         *(new_ptr+ix) = *(*ptr+ix); 
       }
     }
   }
   delete [] *ptr;   
   *ptr = new_ptr;  
 }