加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – SSE类型的容器

发布时间:2020-12-16 07:32:06 所属栏目:百科 来源:网络整理
导读:我试图在SSL容器中存储SSE类型.我试过这个: #include iostream#include vectorint main(){ typedef int v4sf __attribute__ (( vector_size(4*sizeof(float)) )); v4sf a; // compiles std::vectorv4sf v1; // compiles,but nothing is actually allocated/
我试图在SSL容器中存储SSE类型.我试过这个:

#include <iostream>
#include <vector>

int main()
{
  typedef int v4sf __attribute__ (( vector_size(4*sizeof(float)) ));

  v4sf a; // compiles

  std::vector<v4sf> v1; // compiles,but nothing is actually allocated

//  std::vector<v4sf> v2(10); // compiler error: can’t convert between vector values of different size

  std::vector<v4sf> v(10,a); // Compiles,but segfaults

  return 0;
}

但是如上所述,在不提供复制对象的情况下进行分配会产生编译器错误,而分配提供对象时会编译但会出现段错误.任何人都可以解释为什么我不能将这些SSE对象存储在这样的STL容器中(或者更好,提供正确的方法)?

解决方法

要使其正常工作,您必须实现自定义分配器.要使用它,它是类型旁边的参数:
的std ::矢量< SSEType,CustomAlloc>容器;
CustomAlloc是分配器的位置.
你必须使用alligned_malloc或memalign来获取Allocater内存,但这是在这里取得成功的方法.

这里可以找到这样一个例子(不那么容易实现):
Implementing Allocator example

我已经对SSE做了很多,我观察到,这是使用alligned malloc并将其用于我的计算的最简单方法.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读