我可以`__restrict__这个吗? [英] Can I `__restrict__ this` somehow?
问题描述
我一直在观看 Mike Acton在C ++中面向数据的设计讲话 CppCon 2014,他给出了这个例子:
I've been watching Mike Acton's talk on Data-oriented design in C++ in CppCon 2014, and he gives this example:
int Foo::Bar(int count)
{
int value = 0;
for (int i = 0; i < count; i++) {
if (m_someDataMemberOfFoo) value++
}
return value;
}
并解释一些编译器如何保持重读 m_someDataMemberOfFoo
,可能是因为它的值可能会由于并发访问而改变。无论是否适合编译器这样做 - 是否可以告诉编译器在执行某些方法期间特别忽略任何并发访问任何东西的可能性,以便它可以更好地优化?
And explains how some compilers keep re-reading m_someDataMemberOfFoo
in every iteration, perhaps because its value might change due to concurrent access. Regardless of whether it's appropriate for the compiler to do so - can one tell the compiler to specifically ignore any possibility of concurrent access to anything during the execution of some method, so that it may optimize better?
换句话说,我可以告诉编译器这个
是 __ restrict __
p>
In other words, can I tell it the compiler that this
is __restrict__
ed?
推荐答案
-
__ restrict __
在C ++中,所以这个问题只能在一个特定的平台上回答。对于GCC,您可以将__ restrict __
应用于此
const :
__restrict__
is not standardized in C++, so this question can only be answered on a particular platform. For GCC, you can apply__restrict__
tothis
in the same way asconst
:
void T::fn () __restrict__
您的示例中没有潜在的别名。 C ++指定数据竞争的未定义行为。
There is no potential aliasing in your example. C++ specifies undefined behavior for data races.
A 新系统。它可能会在C ++ 17中标准化。支持
A new system for C++ restricted pointers is being developed. It will likely be standardized in C++17. Support for this
is one of the stated design goals.
这篇关于我可以`__restrict__这个吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!