问题描述
是否可以使自定义结构的 std::vector 分配对齐的内存以使用 SIMD 指令进行进一步处理?如果可以使用 Allocator,有没有人碰巧有这样一个他可以共享的分配器?
Is it possible to make std::vector of custom structs allocate aligned memory for further processing with SIMD instructions? If it is possible to do with Allocator, does anyone happen to have such an allocator he could share?
推荐答案
从 C++17 开始,只需使用 std::vector<__m256i> 或任何其他对齐类型.operator new 有对齐版本,它被 std::allocator 用于对齐类型(以及普通的 new 表达式,所以new __m256i[N] 从 C++17 开始也是安全的.
Starting in C++17, just use std::vector<__m256i> or with any other aligned type. There's aligned version of operator new, it is used by std::allocator for aligned types (as well as by plain new-expression, so new __m256i[N] is also safe starting in C++17).
@MarcGlisse 发表了这样的评论,这是一个使其更显眼的答案.
There's a comment by @MarcGlisse saying this, making this an answer to make it more visible.
这篇关于使 std::vector 分配对齐的内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)