boostorg / container

STL-like containers from Boost
http://www.boost.org/libs/container/
Boost Software License 1.0
96 stars 116 forks source link

small_vector cannot go back to use stack space #279

Closed igaztanaga closed 1 month ago

igaztanaga commented 1 month ago

As reported in:

https://stackoverflow.com/questions/54429138/boost-small-vector-cannot-go-back-to-use-stack-space

small vector does not go back to the internal storage even after shrink_to_fit. This behavior is explicitly documented for the class but maybe it should be revisited, specially for shrink_to_fit.

The LLVM implementation does not seem to offer this feature, Folly seems to implement construct + swap to achieve it in shrink_to_fit.

In the same line, in current swap implementation, when one vector uses a dynamic buffer and the other one the internal buffer, swap allocates also a dynamic buffer for the vector with the internal buffer. This should be avoided

igaztanaga commented 1 month ago

The commit https://github.com/boostorg/container/commit/aa35950ca0f8fb82e85a4de71eb77901f5f285d6 finishes changes in small_vector so that: