Opened 9 years ago
Closed 7 years ago
#9165 closed Feature Requests (fixed)
small buffer optimization for vector or new container
Reported by: | Owned by: | Ion Gaztañaga | |
---|---|---|---|
Milestone: | To Be Determined | Component: | container |
Version: | Boost 1.54.0 | Severity: | Optimization |
Keywords: | Cc: |
Description
It is already requested may times (e.g. see http://stackoverflow.com/questions/18530512/stl-boost-equivalent-of-llvm-smallvector). In programs one uses vector's a lot; unfortunately for small containers every time a heady allocation is involved. According to stackoverflow (http://stackoverflow.com/questions/8190950/may-stdvector-make-use-of-small-buffer-optimization), the current standard forbids it. But why not make another container class then? We already have:
- vector
- stable_vector
- static_vector
Change History (3)
comment:1 by , 9 years ago
Status: | new → assigned |
---|
comment:2 by , 7 years ago
Hasn't this now been implemented as [boost::small_vector](http://www.boost.org/doc/libs/master/doc/html/boost/container/small_vector.html)?
comment:3 by , 7 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Closing as small vector was introduced in Boost 1.58
This is an interesting feature that was in the Boost.Container to-do list for a long time. Note that LLVM SmallVector<T, N> is also more flexible than allowing small buffer optimization, as it can be converted to a base SmallVectorImpl<T> class that is independent from N, allowing capacity-independent code:
http://llvm.org/docs/ProgrammersManual.html#llvm-adt-smallvector-h
Small buffer optimization can be achieved (without LLVM capacity-independent Impl class), allowing extended allocator requirements. Currently the STL says for allocator.requirements that:
For SBO allocators (allocators holding an internal buffer) that would no longer be true, so boost::container::vector could support this extended allocators. We'd need to see how this affects to exception safety (swap could throw for throwing copy/move constructors) and it might require extending boost::container::allocator_traits and how vector behaves in copy/move constructor and assignments (¿should this SBO allocator be propagated?).
If this is successful, SBO could be applied to any Boost.Container container.
Implementing LLVM-like capacity-independent features is much tougher, as it might require a really big surgery or writing new classes from the scratch.
I'll start exploring extended allocator requirements for Boost 1.56 or 1.57. Thanks for the ticket and the links.