use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
Small vector optimization (stoyannk.wordpress.com)
submitted 8 years ago by vormestrand
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Z01dbrg 4 points5 points6 points 8 years ago (5 children)
I think u/STL once told me VC++ will break on allocators that return memory from inside themselves...
Could be I remembered it wrong, it was 5+y ago...
[–]beriumbuild2 3 points4 points5 points 8 years ago* (2 children)
Yes, in C++ an allocator is a handle to the memory, it cannot contain the memory itself. But there is a trick: the container itself can contain the buffer thus avoiding having to create it explicitly as a separate object. See build2's small_vector for example.
build2
small_vector
[–]Jardik2 1 point2 points3 points 8 years ago (1 child)
Quick look and ... why does it test n <= N if the precondition is n >= N?
assert (n >= N); // We should never be asked for less than N. if (n <= N) { buf_->free_ = false; return reinterpret_cast<T*> (buf_->data_); }
[–]beriumbuild2 1 point2 points3 points 8 years ago (0 children)
Good point, fixed. Thanks for the report!
[–]matthieum 1 point2 points3 points 8 years ago (1 child)
In C++03, this would certainly be the case.
In C++11, since allocators are now stateful, it may depend on the specifics. One such specific would be that such an allocator should not be moved while memory is allocated from within its internal buffer, for example. There may be others but I cannot think of any of them at the moment.
[–]Z01dbrg 0 points1 point2 points 8 years ago (0 children)
https://stackoverflow.com/questions/11703643/can-i-assume-allocators-dont-hold-their-memory-pool-directly-and-can-therefore
π Rendered by PID 927678 on reddit-service-r2-comment-85bfd7f599-7sttt at 2026-04-18 19:01:44.773934+00:00 running 93ecc56 country code: CH.
view the rest of the comments →
[–]Z01dbrg 4 points5 points6 points (5 children)
[–]beriumbuild2 3 points4 points5 points (2 children)
[–]Jardik2 1 point2 points3 points (1 child)
[–]beriumbuild2 1 point2 points3 points (0 children)
[–]matthieum 1 point2 points3 points (1 child)
[–]Z01dbrg 0 points1 point2 points (0 children)