Alignment of Two Different Data Structures

closed account (zb0S216C)
I've hit a brick wall here. I'm trying to align two data structures (see their layout below) in a single pool of memory. Because the two data structures differ in size and member types, I'm trying to figure out how I should align the two. Here are the structures:-

1
2
3
4
5
6
7
8
9
10
11
struct Alpha
{
    int  DataA_;
    char DataB_;
};

struct Bravo
{
    long long DataA_;
    short DataB_;
};

...and here's the pool which I'm using (condensed):

 
unsigned char *Pool_( static_cast< unsigned char * >( ::operator new( 12u * 8u ) ) );

If an "Alpha" object is placed at the first byte of the pool and a "Bravo" object is placed after the "Alpha" object, how many bytes should I need to align the two objects?

On my x64 machine, "Alpha" is 4-byte aligned and "Bravo" is 8-byte aligned. Note that these are structures used to illustrate my problem. Since I cannot possibly know the layout of each structure placed with the pool, I need some way to align the two structures. Note: I know how data-members are aligned, just not structures.

Any ideas?

Thanks.

Wazzak
Last edited on
Beginners section, huh?

Hmm. Can't you use C++11's alignas for this?
http://en.cppreference.com/w/cpp/language/alignas
Topic archived. No new replies allowed.