Discussion:
[Boost-users] [Boost.Container] Performance of static_vector with default_init_t
d***@gmail.com
2016-12-01 13:09:48 UTC
Permalink
Hi,

I'm constructing a static_vector<double,N>(n, default_init).

I was expecting the constructor call to vanish into just setting the start
pointer and the size & capacity members (and verifying n<=N).

However, the profiler is showing some time spent in the loop
inside uninitialized_default_init_alloc_n
(boost/container/detail/utilities.hpp:678)

For a builtin type and default_init_t, why do we even need to invoke the
allocator? Can't we just leave the memory uninitialized?

This is with Boost 1.55 and VS2008

Thanks in advance
Ion GaztaƱaga
2016-12-04 22:35:55 UTC
Permalink
Post by d***@gmail.com
Hi,
I'm constructing a static_vector<double,N>(n, default_init).
I was expecting the constructor call to vanish into just setting the
start pointer and the size & capacity members (and verifying n<=N).
However, the profiler is showing some time spent in the loop
inside uninitialized_default_init_alloc_n
(boost/container/detail/utilities.hpp:678)
For a builtin type and default_init_t, why do we even need to invoke the
allocator? Can't we just leave the memory uninitialized?
This is with Boost 1.55 and VS2008
Thanks in advance
It should be a no-op, but maybe it is not correctly inlined. With some
compilers I still see some calls to uninitialized_default_init_alloc_n
that disappear when the exception handling part is commented. It seems
that the compiler can't simplify that function enough to make it a no-op.

Could you please try with a more recent Boost version to see if the
problem has improved a bit from your version?

In any case please report a bug to see if something can be done, at
least for POD types.

Ion

Loading...