> Forgive the newbie-type question, but I have a structure that
> I'm trying to make 32 byte aligned for cache efficiency.
The standard says nothing about how to specify alignment, and
alignment varies quite a bit depending on compiler, compiler
flags, architecture, etc - so this isn't a newbie-type question,
IMO. (Nor is the general answer simple.)
Several implmentations have extensions with which to specify
alignment. These are essentially unportable, but sometimes
> I've consulted various sources on this but can't seem to
> come up with a viable soution. My guess is extra padding?
Addiing padding is another way, but IMO it's not much more portable
than the aforementioned compiler-specific extensions. In both
cases you must either decide your code will only support a
particular implmentation (and often, a particular set of compiler
flags as well), or implement build-time logic which detects
implementation characteristics and selects aligment specification
extensions or padding amounts appropriately.
> The entire structure definition:
> #ifdef _MY_ARRAY_ACCESS_STRUCT
> struct MYArray
> MYInt8 *yArrayBuffer;
> MYSize itemCount;
> MYSize itemSize;
> MYSize capacity;
If MYSize is 4 bytes wide, and MYInt8* is also 4 bytes, wide, 16 byte
alignment will give better caching (than 32 byte) because two will
precisely fill 32 bytes.
> typedef struct MYArray MYArray;
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]