如何是一个向量的数据一致? [英] How is a vector's data aligned?

查看:205
本文介绍了如何是一个向量的数据一致?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我要处理的的std ::矢量与上证所的数据,我需要16字节对齐。我怎样才能做到这一点?我是否需要写我自己的分配器?抑或是默认的分配已经对齐到16字节边界?

If I want to process data in a std::vector with SSE, I need 16 byte alignment. How can I achieve that? Do I need to write my own allocator? Or does the default allocator already align to 16 byte boundaries?

推荐答案

C ++标准要求分配函数(的malloc()运算符new() )来分配内存的任何的标准的类型适当对齐。由于这些函数不接受的对齐要求作为一个参数,就实际上,它意味着取向为所有的分配是相同的,是一个标准型具有最大对齐要求,这往往是的取向长双和/或很长很长(见的升压为max_align工会)。

C++ standard requires allocation functions (malloc() and operator new()) to allocate memory suitably aligned for any standard type. As these functions don't receive the alignment requirement as an argument, on practice it means that the alignment for all allocations is the same and is the alignment of a standard type with the largest alignment requirement, which often is long double and/or long long (see boost max_align union).

矢量指令,如SSE和AVX,有较强的调整要求(16字节的128位访问和32字节的256位访问对齐排列)比用标准C ++分配函数提供的。 posix_memalign() memalign可()可以用来满足这样的分配具有较强的调整要求。

Vector instructions, such as SSE and AVX, have stronger alignment requirements (16-byte aligned for 128-bit access and 32-byte aligned for 256-bit access) than that provided by the standard C++ allocation functions. posix_memalign() or memalign() can be used to satisfy such allocations with stronger alignment requirements.

这篇关于如何是一个向量的数据一致?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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