This is the mail archive of the
mailing list for the GCC project.
Re: implementation & optimization of std::function with and without allocator
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: Basile Starynkevitch <basile at starynkevitch dot net>
- Cc: "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>
- Date: Sat, 25 Jan 2014 21:56:24 +0000
- Subject: Re: implementation & optimization of std::function with and without allocator
- Authentication-results: sourceware.org; auth=none
- References: <1390665655 dot 18254 dot 19 dot camel at glinka dot lesours>
On 25 January 2014 16:00, Basile Starynkevitch wrote:
> First, my understanding of the C++11 standard thru
> (which I know is imperfect, but I find it much more readable than
> n3337.pdf draft of C++11 ....)
> is that in principle we should compile this code with the #if 0 replaced
> by #if 1 (but we don't yet, our <functional> header says "TODO: needs
> allocator_arg_t"). Perhaps the type of mygcalloc is wrong...
> (I don't understand at all the issues of accepting allocators for
Using allocators with std::function isn't supported yet. This is
documented at http://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html#status.iso.2011
(and looking at the code, as you have done, should make it pretty
clear the necessary constructors are not defined).
> Then, I am surprised (and a bit disappointed) that (using GCC 4.8.2 from
> Debian) with
> g++-4.8 -Wall -std=c++11 -O3 -S \
> -fdump-tree-phiopt -fverbose-asm testclogc.cc
> we are not inlining all the lambda stuff. I was expecting we'll do the
> inlining, since similar experiments with std::array etc...
That isn't similar and the use of std::array is irrelevant.
std::function involves type erasure, usually dynamic allocation, and
indirection through function pointers. If you don't use std::function
then none of that needs to be optimised away.