title: Data not aligned correctly in Visual Studio if run in debugger
body: <p>I've been working with SSE for a while now, and I've seen my share of alignment issues. This, however, is beyond my understanding:</p>
  
  <blockquote>
    <p>I get different alignment whether I
    run the program using F5 (debug) or
    whether I run it outside the debugger
    (Ctrl+F5)!</p>
  </blockquote>
  
  <p>Some background info:
  I'm using a wrapper for a SSE-enabled datatype - with overloaded operators and custom allocator (overloaded<code>new</code> and <code>delete</code> operators using <code>_mm_malloc</code> and <code>_mm_free</code>). But in the example below, I've managed to reduce to problem even further, i.e. the issue also happens even if I don't use the custom allocator.</p>
  
  <p>As you can see below, in main() I dynamically allocate a TestClass object on the heap, which contains a SSEVector type object. I'm using a dummy <code>float[2]</code> member variable to "missalign" the stack a bit.</p>
  
  <p>I obtain the following output when I run with F5:</p>
  
  <pre><code>object address 00346678
  _memberVariable1 address 00346678
  _sseVector address 00346688
  </code></pre>
  
  <p>And if I run with Ctrl+F5:</p>
  
  <pre><code>object address 00345B70
  _memberVariable1 address 00345B70
  _sseVector address 00345B80
  </code></pre>
  
  <p>As you can see, the alignment is different (i.e. not 16-byte) when I run it in the debugger. Is it just a coincidence that the alignment is correct when using Ctrl-F5? I'm using Visual Studio 2010 with a new project (default settings).</p>
  
  <p>If I declare the object on the stack, i.e. <code>TestClass myObject;</code>, this issue does not appear. Using <code>__declspec(align(16))</code> does not help, either.</p>
  
  <p>The code I used to reproduce the issue:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;xmmintrin.h&gt;  // SSE
  //#include "DynAlignedAllocator.h"
  
  //////////////////////////////////////////////////////////////
  class SSEVector /*: public DynAlignedAllocator&lt;16&gt;*/
  {
  public:
      SSEVector() { }
  
      __m128 vec;
  };
  
  class TestClass
  {
  public:
      TestClass() { }
  
      /*__declspec(align(16))*/ float _memberVariable1 [2];
      SSEVector _sseVector;
  };
  
  //////////////////////////////////////////////////////////////
  int main (void)
  {
      TestClass* myObject = new TestClass;
  
      std::cout &lt;&lt; "object address " &lt;&lt; myObject &lt;&lt; std::endl;
      std::cout &lt;&lt; "_memberVariable1 address " &lt;&lt; &amp;(myObject-&gt;_memberVariable1) &lt;&lt; std::endl;
      std::cout &lt;&lt; "_sseVector address " &lt;&lt; &amp;(myObject-&gt;_sseVector) &lt;&lt; std::endl;
  
      delete myObject;
  
      // wait for ENTER
      std::string dummy;
      std::getline(std::cin, dummy);
  
      return 0;
  }
  </code></pre>
  
  <p>Any hints or commentaries are greatly appreciated. Thanks in advance.</p>