__declspec(align(x)) and virtual tables

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



HI,
I have a class with a virtual table that also has a member that is aligned on 16 bytes : __declspec(align(16)) . The problem is that the virtual table is padded to a size of 16 bytes even if the first member of the class is not the aligned one?!? Is there a way (like a command option) to deactivate this feature, so I can use the lost 12 bytes?


Here is a small exemple of my problem:

///////////////////////////////////////////////
__declspec(align(16))
struct Vector4
{
    float x;
    float y;
    float z;
    float w;
};

struct MyStruct
{
    virtual ~MyStruct() {}

int* ptr; // expected to have it right after the virtual table ptr, but is instead aligned on 16 bytes
Vector4 vec;
};
///////////////////////////////////////////////


I was expecting to have 'MyStruct' and 'MyStruct::vec' aligned on 16 bytes, but not 'MyStruct::ptr'.


BTW, I'm using VisualStudio 2005.


Thanks, Gabriel .



Relevant Pages

  • Re: problem with cast and unions
    ... The part where there is that problem is about conversion from a C float ... to a Small "cell" (actually an int). ... structure, and even then, only if it was NOT the member most recently ... need to declare the union. ...
    (comp.lang.c)
  • Re: Visual C++ Express wont compare object against float in std::upper_bound
    ... Neither order compiles in Debug mode. ... The *original* order compiles in Release mode. ... operator to take two Sample arguments rather than a Sample and a float. ... operator>as member ...
    (microsoft.public.vc.stl)
  • Re: union
    ... Writing a value into one member, ... > will give implementation dependant results. ... > it, as a float, it happens you get a float 0.00000. ... It's probably not exactly zero. ...
    (comp.lang.c)
  • Re: union
    ... stored in the same memory area (large enough to hold the largest union ... Writing a value into one member, ... will give implementation dependant results. ... it, as a float, it happens you get a float 0.00000. ...
    (comp.lang.c)