开发者

[Visual C++]Forcing memory alignment of variables/data-structures

I'm looking at using SSE and I gather aligning data on 16b开发者_Go百科yte boundaries is recommended. There are two cases to consider:

float data[4];

struct myystruct
{
 float x,y,z,w;
};

I'm not sure the first case can be done explicitly, though there's perhaps a compiler option I could use? In the second case I remember being able to control packing in old versions of GCC several years back, is this still possible?


For static array, you can use

__declspec(align(16)) float data[4];

For dynamically allocated array, use _aligned_malloc and _aligned_free. To control structure elements alignment, use #pragma pack.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜