Skip to content
  • Mark OLESEN's avatar
    ENH: refine resizing of zero-sized DynamicList/DynamicField · a16f09b1
    Mark OLESEN authored
    - since List is being used to manage the storage content for
      DynamicList, it needs to free old memory for zero-sized lists first.
    
      Consider this case (slightly exaggerated):
    
          line 0:  DynamicList<label> list;
          line 1:  list.reserve(100000);
          line 2:  list.reserve(200000);
    
      After line 0:
         - list has size=0, capacity=0 and data=nullptr
    
      After line 1:
         - list has size=0, capacity=1e+5 and data != nullptr
    
      After line 2:
         - list has size=0, capacity=2e+5 and data != nullptr
    
      ---
    
      The internal resizing associated with line 1 corresponds to what the
      List resize would naturally do. Namely allocate new storage, copy/move
      any overlapping elements (in this case none) before freeing the old
      storage and replacing with new storage.
    
      Applying the same resizing logic for line 2 means, however, that the
      old memory (1e5) and new memory (2e5) are temporarily both
      accessible - leading to an unnecessary memory peak.
    
      Now: if there is no overlap, just remove old memory first.
    a16f09b1