English 中文(简体)
内存访问与内存副本
原标题:memory access vs. memory copy

I am writing an application in C++ that needs to read-only from the same memory many times from many threads. My question is from a performance point of view will it be better to copy the memory for each thread or give all threads the same pointer and have all of them access the same memory.

谢谢 谢谢

最佳回答

您提供的关于目标系统等的微小信息没有确切的答案,但在普通个人电脑上,最最快的可能是不复制。

复制速度可能很慢的原因之一,就是如果数据区域很大,可能会导致缓存缺失。 普通的 PC 会非常有效地在线条之间缓存对同一数据区域的只读访问,即使这些线索碰巧在不同核心上运行。

英特尔明确列出的用于查封方法的好处之一是"Allows 更多的数据共享机会, 用于在共享缓存的单个核心运行的线条" . I.e. 他们鼓励一种做法,即您不必编程线条来明确隐藏数据, CPU会为你这样做 。

问题回答

既然您具体提到了许多线索, 我假设您至少拥有一个多套套接字系统。 通常, 内存银行与处理器插座有关。 也就是说, 一个处理器“ 最接近” 于自己的存储库, 并且需要与其他处理器回忆控制器进行沟通, 以便访问其他银行的数据 。 (这里的处理器是指套接字中的物理事项)

当您分配数据时,通常使用第一个写法政策来确定您的数据将分配到哪个内存库,这意味着它可以比其他处理器更快地访问它。

因此,至少对于多个处理器(而不仅仅是多个核心)来说,至少每个处理器要分配一个副本,这样应该有一个性能改进。 确定的话, 要用每个处理器/线索而不是主线来分配/ 复制数据( 开发第一个写法政策 ) 。 另外, 您需要确定, 线不会在处理器之间移动, 因为这样您可能会失去与内存的紧密连接 。

我不确定复制单个处理器上每条线索的数据会如何影响性能,但我猜想不复制可以提高共享高层缓存内容的能力,而高层缓存在核心之间共享。

无论如何,根据实际测量结果确定基准和决定。





相关问题
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?

热门标签