Replies: 2 comments
-
作者:杨个毛 愤怒的Linus也是这么想的——Strange sound on mp3 flash websiteLinus Torvalds 2010-11-30 20:50:25 EST(In reply to comment #128)> > In Adobe's software.> > > I'm no great fan of flash but it's an essential part of life on the web these> > days and I had thought that the Fedora project had finally put its days of> > broken flash support behind it.> > Fedora's flash support is fine. Adobe's software is broken.Quite frankly, I find your attitude to be annoying and downright stupid.How hard can it be to understand the following simple sentence: THE USER DOESN'T CARE.Pushing the blame around doesn't help anybody. The only thing that helps is Fedora being helpful, not being obstinate.Also, the fact is, that from a Q&A standpoint, a memcpy() that "just does the right thing" is simply better. Quoting standards is just stupid, when there's two simple choices: "it works" or "it doesn't work because bugs happen".Standards are paper. I use paper to wipe my butt every day. That's how much that paper is worth.Reality is what matters. When glibc changed memcpy, it created problems. Saying "not my problem" is irresponsible when it hurts users. And pointing fingers at Adobe and blaming them for creating bad software is doubly irresponsible if you are then not willing to set a higher standard for your own project. And "not my problem" is not a higher standard.So please just fix it.The easy and technically nice solution is to just say "we'll alias memcpy to memmove - good software should never notice, and it helps bad software and a known problem".(加粗是我加的)当然他这是从库函数的角度来说,他觉得从一开始就干脆搞成memcpy就是memmove,然后就没这么多毛病了。另外有人质疑说到底性能差多少。Linus的Argument是memmove就比memcpy多一条判断指令。我来换句话说,如果反正地址是不重叠的,那么memmove一定可以写成if (地址不重叠) memcpy();的形式。而如果地址是重叠的,速度慢一点的defined behavior总比undefined behavior强。 |
Beta Was this translation helpful? Give feedback.
-
当时我写完这个版本的memcpy/memove导致flash出现strange sound的时候,还专门去https://bugzilla.redhat.com/show_bug.cgi?id=638477#c99 来解释我们为了追求性能需要倒序拷贝。memove比memcpy增加了判断语句就会增加CPU跳转预测出现预测失败的概率,引起其他指令跳转预测的失败。另外由于内存拷贝使用频率较高,我们为了任何点滴的性能都需要花费好大的心思,因此仍然建议在必要的时候使用memcpy. 作者:Ling |
Beta Was this translation helpful? Give feedback.
-
memmove相比memcpy增加了内存重叠的判断,更加安全,效率只是差了那么一丢丢, 为什么经常看见memcpy, 很少看见memmove 呢 ?是不是因为memcpy语义上说明了两段内存是不重叠的所以有些场景使用memcpy 更合适 ?
Beta Was this translation helpful? Give feedback.
All reactions