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:

    It is never the thing but the version of the thing:
    The fragrance of the woman not her self,
    Her self in her manner not the solid block,
    The day in its color not perpending time,
    Time in its weather, our most sovereign lord,
    The weather in words and words in sounds of sound.
    Wallace Stevens (1879–1955)