开发者

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

开发者 https://www.devze.com 2022-12-27 23:23 出处:网络
I\'m looking at using SSE and I gather aligning data on 16b开发者_Go百科yte boundaries is recommended. There are two cases to consider:

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

精彩评论

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

关注公众号