[Development] Question about the QDataBuffer from src/gui/painting

Marc Mutz marc.mutz at kdab.com
Mon Oct 26 09:56:50 CET 2015


On Monday 26 October 2015 08:20:38 Gunnar Sletta wrote:
> I don't know if std::vector::erase() and std::vector::clear() can guarantee
> that the data is not reallocated, even if reserve() has been specified. If
> that can be guaranteed, removing the class would be fine by me.

Since std::vector::erase(f,l) is guaranteed to preserve iterators and 
references to elements before f, no reallocation can occur (unless f == 
begin()).

For clear(), that's not guaranteed, but is a common optimisation. So much so 
that Scott Meyers has an item about how to shed excess capacity in Effective 
STL.

We could add a testcase:

  std::vector<int> v;
  v.resize(1024);
  v.clear();
  QvERIFY(v.capacity() >= 1024);

Thanks,
Marc

-- 
Marc Mutz <marc.mutz at kdab.com> | Senior Software Engineer
KDAB (Deutschland) GmbH & Co.KG, a KDAB Group Company
Tel: +49-30-521325470
KDAB - The Qt Experts



More information about the Development mailing list