title: Why does assignment to an element of an AVX-Vector-wrapper-class-object-array provoke access violation errors?
body: <p>I am trying to do some vector stuff and wrote a wrapper for the m256d datatype from immintrin.h to use overloaded operators.
  The following example should give you a basic idea.</p>
  
  <h3>Class definition</h3>
  
  <pre><code>#include &lt;immintrin.h&gt;
  using namespace std;
  class vwrap {
  public:
    __m256d d;
    vwrap(void) { 
      this-&gt;d = _mm256_set_pd(0.0,0.0,0.0,0.0); 
    }
    void init (const double &amp;a, const double &amp;b, const double &amp;c) { 
      this-&gt;d = _mm256_set_pd(0.0,c,b,a);
    }
  };
  </code></pre>
  
  <h3>Array of vwrap objects</h3>
  
  <p>Let's imagine an array of vwrap that is allocated dynamically:</p>
  
  <pre><code>vwrap *a = (vwrap*) malloc(sizeof(vwrap)*2);
  </code></pre>
  
  <h3>Access violation errors</h3>
  
  <p>Using a function of a vwrap object that contains a mm256-set-function... provokes an access violation error.</p>
  
  <pre><code>a[0].init(1.3,2.3,1.2);
  </code></pre>
  
  <p>The same thing is happening for assigning d with a mm256-set-function 
  (assigning another m256d-object doesn't work as well):</p>
  
  <pre><code>a[0].d = _mm256_set_pd(1,2,3,4);
  </code></pre>
  
  <p>Copying data from another object isn't working, too.</p>
  
  <pre><code>vwrap b;
  a[0].d = b.d;
  </code></pre>
  
  <h3>Stuff that works</h3>
  
  <p>The m256d-object can be manipulated without any problems:</p>
  
  <pre><code>a[0].d.m256d_f64[0] = 1.0;
  a[0].d.m256d_f64[1] = 2.0;
  a[0].d.m256d_f64[2] = 3.0;
  a[0].d.m256d_f64[3] = 4.0;
  </code></pre>
  
  <p>The assignments are working in case of a normal class instance:</p>
  
  <pre><code>vwrap b,c;
  __mm256d t = _mm256_set_pd(1,2,3,5);
  b.d = _mm256_set_pd(1,2,3,4); 
  b.d = t;
  b.d = c.d;
  </code></pre>
  
  <p>I don't get the problem.
  Why can't I use the _mm256 functions (or assign a m256d-object) in case of a class array?
  My only idea is to avoid using the mm256-functions and manipulate the double values directly.
  But this is not what I intentionally wanted to do.</p>