This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[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*).


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]