C ++ STL数据结构调整,算法矢量 [英] C++ STL data structure alignment, algorithm vectorization

查看:179
本文介绍了C ++ STL数据结构调整,算法矢量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法强制执行STL容器对准特定的字节,使用的属性((校))吧?目标的编译器是不是微软的Visual C ++。

Is there a way to enforce STL container alignment to specific byte, using attribute((aligned))perhaps? the target compilers are not Microsoft Visual C++.

什么库,如果有的话,提供的STL算法具有特定明确的矢量,例如专用模板中上证所。我感兴趣的编译器是G ++,Intel和IBM XL。

What libraries, if any, provide specialized templates of STL algorithms which have specific explicit vectorization, e.g. SSE. My compilers of interest are g++, Intel, and IBM XL.

推荐答案

使用STL容器,您可以通过一个可选的模板参数提供你自己的分配器。我不会建议从头开始编写一个完整的分配,但你可以写一个,这只是一个围绕删除但能保证返回的内存满足您的对齐要求。 (例如,如果你需要 N 字节,16字节对齐,可以使用分配 N + 15 字节,并返回一个指向该块中的第一个16字节对齐地址。)

With STL containers, you can provide your own allocator via an optional template parameter. I wouldn't recommend writing an entire allocator from scratch, but you could write one that's just a wrapper around new and delete but ensures that the returned memory meets your alignment requirement. (E.g., if you need n bytes with 16-byte alignment, you use new to allocate n + 15 bytes and return a pointer to the first 16-byte aligned address in that block.)

但它可能是滥竽充数的对齐属性添加到元素类型。这是标准的范围之内,所以你必须检查你的编译器文档和尝试。

But it might be enough just to add the alignment attribute to the element type. That's outside the scope of the standard, so you'd have to check your compiler documentation and try it.

这篇关于C ++ STL数据结构调整,算法矢量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆