是否可以使自定义结构的 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 分配对齐的内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!