- #1
Dissident Dan
- 238
- 2
Has anyone else experience the new operator not working correctly for 16-byte aligned data types? I am using Visual Studio .NET 2003.
I have a class that has its first component 16 byte-aligned via the "__declspec(align(16))" directive because I am using SSE.
When dynamically allocating and array of this class using the new operator, I get an 8 byte-aligned pointer. It needs to be 16 byte-aligned to not crash when using SSE intrinsics.
I have even tried using "__declspec(align(16))" on the pointer and between the "new" and the data type. Example:
I have resorted to using the old C functions _aligned_malloc() and _aligned_free().
This must be a bug with Visual Studio, right? Anyone know of any fixes?
I have a class that has its first component 16 byte-aligned via the "__declspec(align(16))" directive because I am using SSE.
Code:
class Vector {
public:
// data members
union {
__declspec(align(16)) float comps[4];
struct {
float x,y,z,w;
};
struct {
float r, g, b, a;
};
struct {
float yaw, pitch, roll;
};
};
When dynamically allocating and array of this class using the new operator, I get an 8 byte-aligned pointer. It needs to be 16 byte-aligned to not crash when using SSE intrinsics.
I have even tried using "__declspec(align(16))" on the pointer and between the "new" and the data type. Example:
Code:
__declspec(align(16)) Vector *tan1 = new __declspec(align(16)) Vector[vertexCount * 2];
I have resorted to using the old C functions _aligned_malloc() and _aligned_free().
This must be a bug with Visual Studio, right? Anyone know of any fixes?
Last edited: