Template for quick copy in C

I once saw a programming pattern (not a design) how to implement a quick copy of buffers. It included an alternating cycle and a switch. The fact is that he copied 4 bytes most of the time, only the last few bytes of the buffer were copied using smaller data types.

Can someone tell me his name? It is named after a man. This is done in C, and the compiler output is almost optimal.

+3
source share
4 answers

Sounds like you're thinking of a Duff device .

+11
source

memcpy(), , .

+12
+2
source

It's called a Duff device, see Wikipedia .

If you want to implement / use a quick copy, first look at the implementation of your compiler; it can use a much more complex algorithm, using the advanced features of your processor. For example, Intel compilers have rather complex versions.

+2
source

Source: https://habr.com/ru/post/1717418/


All Articles