Why is memmove faster than memcpy?

后端 未结 4 759
灰色年华
灰色年华 2020-12-12 15:01

I am investigating performance hotspots in an application which spends 50% of its time in memmove(3). The application inserts millions of 4-byte integers into sorted arrays,

4条回答
  •  星月不相逢
    2020-12-12 15:12

    When you are using memcpy, the writes need to go into the cache. When you use memmove where when you are copying a small step forward, the memory you are copying over will already be in the cache (because it was read 2, 4, 16 or 128 bytes "back"). Try doing a memmove where the destination is several megabytes (> 4 * cache size), and I suspect (but can't be bothered to test) that you'll get similar results.

    I guarantee that ALL is about cache maintenance when you do large memory operations.

提交回复
热议问题