English 中文(简体)
无效记忆存取和分辨率
原标题:Pointer indirection check for invalid memory access and segmentation fault
struct A { int i; };
...
A *p = (A*) (8); // or A *p = 0;
p->i = 5;    // Undefined Behavior according C/C++ standard

However, practically most of the system would crash (segmentation fault) for such code.

Does it mean that all such Architectures/Systems have a hidden check for pointer indirection (i.e. p->) to verify if it s accessing a wrong memory location ?

If yes, then it implies that even in perfectly working code we are paying the price for that extra check, correct ?

最佳回答

无,不正确。 由于以下两个原因,绝对需要对有效记忆存取进行同样的检查:

1) Otherwise, how would the system know what physical memory you were accessing and whether the page was already resident?

(2) 否则,如果实际记忆变得紧张,操作系统将如何知道哪几页的实物记忆?

It s integrated into the entire virtual memory system and part of what makes modern computers perform so amazingly well. It s not any kind of separate check, it s part of the process that determines which page of physical memory the operation is accessing. It s part of what makes copy-on-write work. (The very same check detects when a copy is needed.)

问题回答

There are generally no extra hidden checks, this is just an effect of using virtual memory.

Some of the potential virtual addresses are just not mapped to physical memory, so translating things like 8 will likely fail.

Yes, you are paying the price for that extra check. It s not just for pointer indirection, but any memory access (other than, say, DMA). However, the cost of the check is very small.

  • While your process is running, the page table does not change very often. Parts of the page table will be cached in the translation lookaside buffer, accessing pages with entries in the buffer incur no additional penalty.

  • 如果您的工作能够进入一个没有TLB进入的网页,那么,CPU必须增加记忆,使该页页的页表进入。 之后,将安排时间。

你们可以通过起草试验方案来看待这一效果。 • 抽取你的试样方案,并随机抽取和书写记忆。 利用指挥线参数改变规模。

  • Above the L1 cache size, performance will drop due to L2 cache latency.
  • Above the L2 cache size, performance will drop to RAM latency.
  • Above the size of the memory addressed by the TLB, performance will drop due to TLB misses. (This might happen before or after you run out of L2 cache space, depending on a number of factors.)
  • Above the size of available RAM, performance will drop due to swapping.
  • Above the size of available swap space and RAM, the application will be terminated by the OS.

如果您的运行系统允许“大页”,TLB可能实际上能够覆盖一个非常大的地址空间。 也许你可以通过从<条码>mmap中分配4k chunks来破坏本组织,在这种情况下,根据你的处理者,TLB misses可能只感受几个工作套。

<>光> 必须根据虚拟记忆的惠益来权衡业绩下降幅度较小的情况,而虚拟记忆的惠益太大,无法在此列出。

分裂错误是试图获取传记,而公民保护委员会不能实际处理。 发生这种情况的是,这些硬件向一个操作系统发出有关侵犯记忆的信号。 因此,我认为,如果试图进入记忆地点,硬件无法向后来向造成例外的程序发出信号的监督厅发出信号,就没有进行额外的核对。 接收信号的过程不成事实,就把核心信息倾斜并终止。





相关问题
Undefined reference

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 ...

C++ Equivalent of Tidy

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 ...

Template Classes in C++ ... a required skill set?

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?

Print possible strings created from a Number

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->...

typedef ing STL wstring

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, ...

C# Marshal / Pinvoke CBitmap?

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 ...

Window iconification status via Xlib

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?

热门标签