This is the mail archive of the
mailing list for the libstdc++ project.
[RFC] Should we increase the small-object buffer in std::any?
- From: Jonathan Wakely <jwakely at redhat dot com>
- To: libstdc++ at gcc dot gnu dot org
- Date: Tue, 9 Oct 2018 09:41:49 +0100
- Subject: [RFC] Should we increase the small-object buffer in std::any?
Before we declare C++17 support non-experimental we should consider
some breaking changes to our C++17 types. For example, we could make
std::any larger, so that it can store larger objects internally
without heap allocation.
Currently it has a buffer of sizeof(void*) bytes, which either stores
a small object inline, or stores a pointer to an object on the heap.
The std::any needs a pointer to the "manager function" as well, so
sizeof(any) is two pointers. Libc++ has a 3*sizeof(void*) buffer, so
sizeof(any) is four pointers. For MSVC sizeof(any) is eight pointers!
Obviously there's a trade-off here, and I don't have any usage data to
make a good decision.
If we make the buffer bigger then we avoid the heap more often, but
when we do still need to use the heap there's wasted space in the
std::any (because we only need enough room for a void*).