Boost logo

Boost Users :

From: Gennadiy Rozental (gennadiy.rozental_at_[hidden])
Date: 2005-08-24 15:22:33


"Kim Barrett" <kab_at_[hidden]> wrote in message
news:p06230904bf327ef3cc00@[192.168.161.194]...
> At 12:38 PM -0400 8/24/05, Gennadiy Rozental wrote:
>>"Kim Barrett" <kab_at_[hidden]> wrote in message
>>news:p06230900bf3241d57905@[192.168.161.194]...
>>> At 1:25 AM -0400 8/23/05, Gennadiy Rozental wrote:
>>>>template<typename F>
>>>>class global_fixure_impl : public global_fixure {
>>>> virtual void setup() { new (m_space) F; }
>>>> virtual void teardown() { ((F*)m_space)->~F(); }
>>>>
>>>> char m_space[sizeof(F)];
>>>>};
>>>
>>> Alignment of m_space must be appropriate for the alignment of F. I
>>> think
>>> this can be addressed by putting m_space in a union with a value whose
>>> type
>>> is the result of
>>> boost::type_with_alignment<boost::alignment_of<F>::value>::type.
>>
>>char m_space[sizeof(F)]; is going to be aligned properly automatically
>
> I don't see how. See analogous discussion recently on boost developers
> list
> under subject "alignment problem in proposed any alternative", in
> particular
> the message from Martin Bonner on 8/11/05:
> http://aspn.activestate.com/ASPN/Mail/Message/boost/2772775
> Otherwise, what would be the point of boost::aligned_storage (which
> actually
> packages up the union idiom I was suggesting be used)?

You maybe right. I will use new then,

virtual void setup() { m_space = new char[sizeof(F)]; new (m_space) F; }
virtual void teardown() { ((F*)m_space)->~F(); delete m_space; }
char* m_space;

Gennadiy


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net