Mayfly A Pattern for Lightweight Generic Interfaces

Jeremy G. Siek, Andrew Lumsdaine · 1999

The Mayfly pattern describes an implementation approach to constructing interfaces for efficient data structures. In Nature, the mayfly is a creature well known for its short life span. Similarly, for our purposes, a Mayfly is a temporary object that resides on the stack or only in registers (never in the heap). All of its member functions are typically inlined and it is always passed by value. These characteristics make Mayfly objects ideal for providing lightweight interfaces to efficient array-based data structures such as compressed matrices, graphs, heaps, and trees. The Mayfly pattern cuts across several other patterns. For instance, many of the iterators in the Standard Template Library (STL [1, 19]) are Mayflies. Among the Mayflies described in this paper will be some Adapter [3] 1 and Aggregate [3, 14] objects. 1Intent Implement lightweight interfaces for efficient data structures using small temporary objects. 2 Motivation Many times the most efficient implementa...

Read the paper · More papers on PaperTik