qt vector reallocation during append()
-
i was looking through qt vector append() source and i noticed that reallocation during insertion doesn't work alike std::vector. the latter allocates a new memory of size
size * 1.5
while qt vector allocates a new memory ofsize + 1
. why is this difference? also, this makes append linear, so what's the good? -
Hi,
That's a question better asked on the interest mailing list. You'll find there Qt's developers/maintainers. This is forum is more user oriented.
-
@user4592357 said in qt vector reallocation during append():
while qt vector allocates a new memory of size + 1
This is absolutely wrong. It just passes the new size to an internal function named realloc. What you miss is that the second parameter is set to QArrayData::Grow which will do the right thing.
-
@Christian-Ehrlicher
okay, so what's the size of the new vector, after re-allocation? -
@user4592357 said in qt vector reallocation during append():
what's the size of the new vector
The size is oldSize+1, the reseved size can be seen with capacity()
/edit: simply following the calls you will get to this function: qCalculateGrowingBlockSize