Duff's Device - Stroustrup's Version

Stroustrup's Version

The original Device was made for copying to a (memory-mapped) register. To actually copy memory from one location to another, an auto-increment must be added to every reference to to, like so:

*to++ = *from++;

This modified form of the Device appears as a "what does this code do?" exercise in Bjarne Stroustrup's book The C++ Programming Language, presumably because novice programmers cannot be expected to know about memory-mapped output registers. However, the standard C library provides the function memcpy for this purpose; it will not perform worse than this code, and may contain architecture specific optimizations that will make it significantly faster.

Read more about this topic:  Duff's Device

Famous quotes containing the word version:

    If the only new thing we have to offer is an improved version of the past, then today can only be inferior to yesterday. Hypnotised by images of the past, we risk losing all capacity for creative change.
    Robert Hewison (b. 1943)