1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Aligned allocation and VC++.NET

  1. Oct 23, 2005 #1
    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.

    Code (Text):

    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 (Text):

    __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: Oct 23, 2005
  2. jcsd
  3. Oct 23, 2005 #2

    dduardo

    User Avatar
    Staff Emeritus

    You're probably going to need to post this on a microsoft newsgroup or forum. I'm not familiar with MS specific code. In gcc __attribute__ (aligned(16)) is used.

    [edit] This is just a guess, but when using __attribute__ I believe it goes after the allocation statement. Something like this:

    float comps[4] __attribute__ (aligned(16));

    This might be the same case with __delcspec
     
    Last edited: Oct 23, 2005
  4. Dec 3, 2005 #3
  5. Feb 19, 2008 #4
  6. Mar 5, 2008 #5

    zyh

    User Avatar

    The help file( CHM ) supplied by intel c++ compiler hase some example on this topic. Also, www.codeproject.com hase some articles to introduce SSE.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: Aligned allocation and VC++.NET
  1. Visual basic .net 2008 (Replies: 0)

Loading...