MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/cpp/comments/1p03bw/stl_is_dated/ccxzirb/?context=3
r/cpp • u/meetingcpp Meeting C++ | C++ Evangelist • Oct 22 '13
14 comments sorted by
View all comments
2
One thing that always bugged me about allocators:
pointer allocate( size_type n, std::allocator<void>::const_pointer hint = 0 );
is that I require storage for at least N instances, and the allocator may allocate more... but I have no way of knowing so.
If you think about std::vector this is pretty damning:
std::vector
I ask for 3 elements
The allocator has a bucket for 2 and a bucket for 5, it serves me the bucket for 5
I push a 4th element: reallocation!
I vie for having allocate be:
allocate
std::pair<pointer,size_type> allocate(size_type n, ...);
where the result .second member is guaranteed to be superior to n.
.second
n
2 u/more_exercise Lazy Hobbyist Oct 23 '13 superior to nWould you be fine with .second >= n? Or are you requiring .second > n? 1 u/matthieum Oct 25 '13 I am fine with >= n, since I needed at least n.
superior to n
Would you be fine with .second >= n? Or are you requiring .second > n?
1 u/matthieum Oct 25 '13 I am fine with >= n, since I needed at least n.
1
I am fine with >= n, since I needed at least n.
>= n
2
u/matthieum Oct 23 '13
One thing that always bugged me about allocators:
is that I require storage for at least N instances, and the allocator may allocate more... but I have no way of knowing so.
If you think about
std::vectorthis is pretty damning:I ask for 3 elements
The allocator has a bucket for 2 and a bucket for 5, it serves me the bucket for 5
I push a 4th element: reallocation!
I vie for having
allocatebe:where the result
.secondmember is guaranteed to be superior ton.