Re: Alignment
On Feb 26, 12:11 pm, Greg Herlihy <gre...@mac.com> wrote:
On Feb 26, 10:36 am, better_cs_...@yahoo.com wrote:
On Feb 26, 11:18 am, Gert-Jan de Vos <gert-
To force the unsigned char array to have the same alignment as the Foo
(which is my goal), I'd like to put these together in a union.
However, Foo has a non-trivial constructor, so it may not be a member
of a union. Do I have any othre options?
Allocate the char array dynamically:
char * fooArray = new char[sizeof(Foo)];
Now fooArray will be suitably aligned for a Foo type.
Greg
Unfortunately, allocating on the heap is verboten in our application.
Whether it makes sense or not, it is what it is and it will not pass
the design review.
The memory I'm trying to get properly aligned is actually going to be
static in a class and will have a singleton instance of the class
constructed in it via placement new.
class Foo
{
...
static unsigned char s_pInstance[];
};
unsigned char Foo::s_pInstance[sizeof(Foo)]; // Will have a Foo
constructed in it
The goal is to ensure that s_pInstance is suitably aligned to hold a
Foo. Is this possible within the bounds of the C++ language standard,
or is it an architecture issue (in which case I'm in the wrong group)?