SSE and C++ containers

前端 未结 4 1234
情书的邮戳
情书的邮戳 2020-12-09 20:26

Is there an obvious reason why the following code segfaults ?

#include 
#include 

struct point {
    __m128i v;

  point()          


        
4条回答
  •  一整个雨季
    2020-12-09 21:00

    The vector constructor you are using is actually defined like this:

    explicit vector ( size_type n, const T& value= T(), const Allocator& = Allocator() );
    

    (see e.g., http://www.cplusplus.com/reference/stl/vector/vector/).

    In other words, one element is default constructed (i.e., the default parameter value as you call the constructor), and the remaining elements are then created by copying the first one. My guess is that you need a copy constructor for point that properly handles the (non-)copying of __m128i values.

    Update: When I try to build your code with Visual Studio 2010 (v. 10.0.30319.1), I get the following build error:

    error C2719: '_Val': formal parameter with __declspec(align('16')) won't be aligned c:\program files\microsoft visual studio 10.0\vc\include\vector 870 1   meh
    

    This suggests Ben is right on the money regarding this being an alignment problem.

提交回复
热议问题