proxygen
|
folly::small_vector<T,Int=1,...>
is a sequence container that implements small buffer optimization. It behaves similarly to std::vector, except until a certain number of elements are reserved it does not use the heap.
Like standard vector, it is guaranteed to use contiguous memory. (So, after it spills to the heap all the elements live in the heap buffer.)
Simple usage example:
This class is useful in either of following cases:
std::vector
's capacity tracking. This vector lets malloc
track our allocation capacity. (Note that this slows down the insertion/reallocation code paths significantly; if you need those to be fast you should use fbvector
.)The last two cases were the main motivation for implementing it.
There are also a couple of flags you can pass into this class template to customize its behavior. You can provide them in any order after the in-place count. They are all in the namespace small_vector_policy
.
NoHeap
- Avoid the heap entirely. (Throws std::length_error
if you would've spilled out of the in-place allocation.)<Any integral type>
- customizes the amount of space we spend on tracking the size of the vector.A couple more examples: