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:

    I should think that an ordinary copy of the King James version would have been good enough for those Congressmen.
    Calvin Coolidge (1872–1933)