Reputation: 10808
I once saw a programming pattern (not design), how to implement a fast copy of buffers. It included an interleaved loop and switch. The thing was, it copied 4 bytes most of the time, only the last few bytes of the buffer were copied using smaller datatypes.
Can someone tell me the name of it? It's named after a person. It's done in C and the compiler output is nearly optimal.
Upvotes: 3
Views: 2148
Reputation: 719
It is called Duff's device, see on Wikipedia
If you want to implement / utilize a fast copy, then first look at your compiler's implementation; it might use a lot more sophisticated algorithm using advanced features of your CPU. The Intel compilers have pretty sophisticated versions for example.
Upvotes: 2
Reputation: 19243
Use memcpy()
, it's standard, portable and in many cases optimized well too.
Upvotes: 12