Add tunable_vector std::vector wrapper container#746
Conversation
0c289ed to
b2c561e
Compare
Add tunable_vector memory alias to `core/memory`
d00c51f to
27db712
Compare
It shouldn't depend on that based on the code I read. |
| } | ||
|
|
||
| template< | ||
| typename T, _detail::tunable_growth_trait GrowthTrait = growth_traits<2, 1>, typename Allocator = std::allocator<T>> |
There was a problem hiding this comment.
Doubling creates memory fragmentation as the sum of your old memory would be 2^n -1 and you need 2^n.
The upper bound that avoids this is the golden ratio ~1.6 so 1.5 would be a better default
| constexpr void append_range(RangeT&& range) { | ||
| if constexpr (std::ranges::forward_range<RangeT> || std::ranges::sized_range<RangeT>) { | ||
| reserve_minimum(std::ranges::distance(range)); | ||
| std::ranges::move(range, std::back_inserter(*this)); |
There was a problem hiding this comment.
Not ranges v3?
or std::uninitialized_copy + resize?
|
|
||
| constexpr void resize(size_type count) { | ||
| if (size() == capacity()) { | ||
| reserve_minimum(count); |
There was a problem hiding this comment.
That's unexpected. resize normally does not trigger a reallocation unless you lack capacity
| } | ||
|
|
||
| if (value > new_capacity) { | ||
| return value; |
There was a problem hiding this comment.
This seems wrong.
Say you reserve for value and fill it to or near value then add 1-3 elements, it would have to reallocate again.
It would make more sense if it:
- reserves for value + buffer size
- reserves for value x factor
- reserves for smallest factor^n that fits value (+ buffer)
core/stl/containers#744Add tunable_vector memory alias to
core/memory