From: Fernando Cacciola (fcacciola_at_[hidden])
Date: 2003-04-19 22:31:45
"Joel de Guzman" <djowel_at_[hidden]> escribió en el mensaje
> Giovanni Bajo wrote:
> > (sorry for the previous empty post)
> > Hello,
> > Since the aligned storage "wastes" bytes to align the type, is it
> > possible to place the boolean "m_initialized" within the alignment
> > padding? Basically, you could define dummy.data one byte bigger,
> > and use it for m_initialized. This way, you could save space in many
> > situations.
> > I would propose a patch but I don't understand all the details of the
> > alignment issues. Besides, I'm not sure it would be legal to do so.
Hmmm. Sounds like an interesting optimization.
Thanks for bringing it up!
> Heh, I was just thinking about this the other day...
> Right off the bat, we can detect at compile-time if the padding
> is non-zero and stuff m_initialized in the padding if it is not.
This looks like a feasible way to do it.
> I think this can be done by putting the m_initialized handling
> in the aligned_storage template.
The only drawback of this is that an aligned_storage,
conceptually, might not have a non-initialized state,
so this additional flag might look akward for
some other uses of aligned_storage.
In particular, I think that the variant library
won't have any use for it.
Currently, optional<> is using its own aligned_storage
template, but this is because I've found that the
aligned_storage as it was designed for both optional
and variant ICEed BCB5 on some particular cases,
so I had to provide a custom template; but I intend
to find a 'general' version of aligned_storage that
can be used by optional and variant at the same time.
> There will be a specialization
> for the case where the padding is non-zero and the flag is placed
> in the padding and another specialization for the case where padding
> is zero and the flag is a data member. Generic accessor member functions
> can be provided: bool is_initialized() const, void is_initialized(bool f);
We might come to conclude that the 'initialized' flag is approptiate even
for a general 'aligned_storage' facility. In this case,
I think your technique will work.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk