How do realloc and memcpy work?
问题 I have two questions. 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 ? 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: 1 - No. They copy a block at a time. See http://www.embedded.com/design/configurable-systems/4024961