How do realloc and memcpy work?

前端 未结 8 1063
遇见更好的自我
遇见更好的自我 2020-12-01 02:49

I have two questions.

  1. Do realloc() and memcpy() copy the entries in an array to another in a way faster than just iterating on eac

8条回答
  •  伪装坚强ぢ
    2020-12-01 03:29

    1. It can be conjectured that memcpy could be written such that it would move large number of bits around. e.g. It's entirely possible to copy the data using SSE instructions, if it is advantageous.

    As other said, it won't be faster than O(n), but memory systems often have a preferred block size, and also it's possible to, say, write the size of a cache line at a time.

提交回复
热议问题