This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [RFC] Should we increase the small-object buffer in std::any?
- From: Ville Voutilainen <ville dot voutilainen at gmail dot com>
- To: Jonathan Wakely <jwakely at redhat dot com>
- Cc: "libstdc++" <libstdc++ at gcc dot gnu dot org>
- Date: Tue, 9 Oct 2018 13:47:15 +0300
- Subject: Re: [RFC] Should we increase the small-object buffer in std::any?
- References: <20181009084149.GK23172@redhat.com>
On Tue, 9 Oct 2018 at 11:42, Jonathan Wakely <jwakely@redhat.com> wrote:
>
> 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*).
I don't have a strong opinion, I have no idea what size would be more
optimal more often. The current size
is kinda 'safe' in the sense that it doesn't waste any space for the
allocated cases. The frequency of allocated vs.
inline is a complete mystery to me.