[Development] QVector reserve counterproductive?
Christian Ehrlicher
Ch.Ehrlicher at gmx.de
Sat Mar 3 21:38:12 CET 2018
Hi,
while digging through the bugreports I found
https://bugreports.qt.io/browse/QTBUG-66677 which seems to show a
downside of QVector::reserve().
QPainterPath::addPolygon() is calling reserve() to make sure to have
enough space for the new positions. This is exactly what I would have
done and what e.g. CLazy suggests. But it looks like reserve() allocates
*exactly* the amount of elements given. Therefore calling addPolygon() a
second time will do a new reallocation and so on.
The documentation for reserve() only states that memory for 'at least
size elements' is allocated so my naive assumption would be that calling
reserve a second time with a slightly bigger value than before does
nothing. But this doesn't seem to be the case here.
For the bug: removing the reserve() inside addPolygon() fixes the speed
issues mentioned in the bug report. Don't know if the bug report is a
valid use case though.
Thx,
Christian
More information about the Development
mailing list