怎样的realloc和memcpy工作? [英] How do realloc and memcpy work?
问题描述
亲爱的,这里是我的问题...
Dear all, Here are my questions...
1做的realloc和memcpy阵列中的复制项到另一个的方式更快的不仅仅是遍历每个元素O(N)?如果答案是肯定的话,你认为什么是它的复杂性?
1- Do realloc and memcpy copy the entries in an array to another in a way faster than just iterating on each element O(N) ? If the answer is yes then what do you think is its complexity ?
2 - 如果分配的大小比原来的尺寸小,不realloc的条目复制到别的地方或刚刚离开他们,因为他们正在减少数组的大小?
2- If the size allocated is smaller than the original size, does realloc copy the entries to somewhere else or just leave them as they are decreasing the size of the array ?
太感谢了。
推荐答案
1 - 他们一次复制的块号。见的http://www.embedded.com/design/configurable-systems/4024961/Optimizing-Memcpy-improves-speed为pretty很好的分析。
1 - No. They copy a block at a time. See http://www.embedded.com/design/configurable-systems/4024961/Optimizing-Memcpy-improves-speed for a pretty good analysis.
2 - 这是实现有关。请参见 http://www.gnu.org/software/ libtool的/手动/的libc /更改-块Size.html 以glibc的详细信息。 在几个分配的实现,使得块较小,有时就必须将它复制
2 - This is implementation dependent. See http://www.gnu.org/software/libtool/manual/libc/Changing-Block-Size.html for glibc details. "In several allocation implementations, making a block smaller sometimes necessitates copying it"
这篇关于怎样的realloc和memcpy工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!