
On 6/28/06, Joaquín Mª López Muñoz <joaquin@tid.es> wrote:
During some conversations with a colleague I came up with a very sketchy realization of what could be converted, if there is interest, in a flyweight library. Please see flyweight.hpp at Vault/Patterns:
The so-called Flyweight Design Pattern, upon which this is inspired, is much too OO for current C++ tastes IMHO, what I'm proposing takes a more generic stance. A minimal use example follows showing the syntax:
#include "flyweight.hpp" #include <string> #include <iostream>
int main() { using boost::flyweight::flyweight;
flyweight<std::string> str("hello world"); std::cout<<str<<"\n"; }
Briefly put, a flyweight<T> is an object that can be used as a const T (i.e. flyweight<T> provides an operator const T&) but whose size is that of a pointer. The trick is that identical flyweight<T> objects share their representation globally, which drastically reduces memory usage when there are much more objects than different values. Additionally, comparison of flyweight objects can be made faster than that of the underlying type T, since we it reduces to pointer comparison
--contrast that with what takes to compare the underlinyg type T when T=std::string, for instance.
So, is there interest in having such a lib in Boost? Please note that the provided implementation is still a primitive one, but OTOH it does have all the advertised functionality, so one can use it to test it locally and form an opinion about its suitability: if somebody, for instance, can plug it into some scenario with massive quantities of elements, I'd appreciate knowing about resulting memory and performance improvements.
In case this raises interest, I can turn the thing into a more fleshed out proposal during the summer.
This library seems like it could be excellent, lets get a review going! As others have noted, of all the languages I have looked at, I've never heard the term "flyweight", only "interned". Where does "flyweight" come from? This library might get more recognition if it used the more common name.
Thank you for your attention,
Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
-- Cory Nelson http://www.int64.org