You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Data structures need to be aligned to 16 bytes for efficient SIMD loads and stores.
Also, data structures are often desired to be emdedded inside std::vectors.
If the data structure has declspec(align) members, it cannot be embedded into a std::vector.
As a workaround, provide something like the following scheme:
class float4_unaligned
{
float x,y,z,w;
__m128 sse;
};
Data structures need to be aligned to 16 bytes for efficient SIMD loads and stores.
Also, data structures are often desired to be emdedded inside std::vectors.
If the data structure has declspec(align) members, it cannot be embedded into a std::vector.
As a workaround, provide something like the following scheme:
class float4_unaligned
{
float x,y,z,w;
__m128 sse;
};
typedef __declspec(align (16)) float4_unaligned float4;
// Use case 1 on the stack:
float4 x; // Will be aligned.
// Use case 2 in a vector:
vector<float4_unaligned, custom_16_aligned_allocator> vectorOfFloats; // Will be aligned. See aligned allocator here http://www.velocityreviews.com/forums/t646180-make-stl-containers-allocate-aligned-memory.html
vector<float4_unaligned> vectorOfFloats; // Wouldn't be aligned, and crash at runtime.
vector vectorOfFloats; // Wouldn't probably compile due to http://stackoverflow.com/questions/1281415/error-c2719-val-formal-parameter-with-declspecalign16-wont-be-alig
The text was updated successfully, but these errors were encountered: