这里的问题是:。 利用<代码>std: 填满(<>>>> 本身获得一定帮助——汇编者可能决定后不得进入记忆组,从而消除这一障碍是时间的浪费,消除了记名。
{
char buffer[size];
//obtain and use password
std::fill_n( (volatile char*)buffer, size, 0);
}
目的是在看到<代码>volatus时。 汇编者不会试图取消对<代码>以下的号召:填充(n)()。
这里的问题是:。 利用<代码>std: 填满(<>>>> 本身获得一定帮助——汇编者可能决定后不得进入记忆组,从而消除这一障碍是时间的浪费,消除了记名。
{
char buffer[size];
//obtain and use password
std::fill_n( (volatile char*)buffer, size, 0);
}
目的是在看到<代码>volatus时。 汇编者不会试图取消对<代码>以下的号召:填充(n)()。
编辑可在because buffer<>/code>上优化你的代码。 这不是一个挥发性物体
。
《标准》只要求汇编者严格遵守挥发性物体的特性。 这里指的是C++03。
符合执行要求的要求最少:
- At sequence points, volatile objects are stable in the sense that previous evaluations are complete and subsequent evaluations have not yet occurred. [...]
以及
The observable behavior of the abstract machine is its sequence of reads 以及writes to volatile data and calls to library I/O functions
In your example, what you have are reads 以及writes using volatile lvalues to non-volatile objects. C++0x removed the second text I quoted above, because it s redundant. C++0x just says
符合执行要求的要求最少:
- Access to volatile objects are evaluated strictly according to the rules of the abstract machine.[...]
这些方案统称为
值得注意的行为。
While one may argue that "volatile data" could maybe mean "data accessed by volatile lvalues", which would still be quite a stretch, the C++0x wording removed all doubts about your code 以及clearly allows implementations to optimize it away.
But as people pointed out to me, It probably does not matter in practice. A compiler that optimizes such a thing will most probably go against the programmers intention (why would someone have a pointer to volatile otherwise) 以及so would probably contain a bug. Still, I have experienced compiler vendors that cited these paragraphs when they were faced with bugreports about their over-aggressive optimizations. In the end, volatile
is inherent platform specific 以及you are supposed to double check the result anyway.
从最后的C++0x草案[生效]:
8 The least requirements on a conforming implementation are:
— Access to volatile objects are evaluated strictly according to the rules of the abstract machine.
[......]
12 Accessing an object designated by a volatile glvalue (3.10), modifying an object, calling a library I/O function, or calling a function that does any of those operations are all side effects, [......]
因此,即使你提供的法典也不得优化。
您希望删除的记忆内容可能已经从贵邮联/核心内藏中流出到援助团,在那里其他邮联能够继续看到。 在撰写文章后,你需要使用双向/记忆屏障指示/原子操作或某种东西,以引发与其他核心的结合。 在实践中,贵编者在要求任何外部职能之前,或许会这样做(戈格尔·达维·布滕金在多读过程中挥发的可疑用途上担任职务),这样,如果你在不久之后准备好,不会成为一个重大问题。 简言之,需要挥发性。
符合要求的执行在休闲时,可推迟任何挥发性的读写字的实际表现,直至变幻莫测的读写结果会影响执行挥发性书写或I/O操作。
例如:
volatile unsigned char vol1,vol2;
extern unsigned char res[1000];
void test(int scale)
{
unsigned char ch;
for (int 0=0; i<10000; i++)
{
res[i] = i*vol1*scale;
vol2 = res[i];
}
}
a 符合规格的汇编者可在其选择中核对<代码>> > > 比例代码> 是128的多种,如果是,在从<代码>vol1做任何读物之前,从<代码>中删除。 页: 1 即使汇编者需要从<代码>vol1上读出。 在编汇到<代码>第2卷<>>代码>之前,编汇人可推迟两个业务,直至其操作基本不受限制的代码。
I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...
I have been searching for sample code creating iterator for my own container, but I haven t really found a good example. I know this been asked before (Creating my own Iterators) but didn t see any ...
Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...
I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?
Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...
Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...
I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...
Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?