
A customizable C++ framework - ingve
https://akrzemi1.wordpress.com/2016/01/16/a-customizable-framework/
======
apaprocki
Just as a counter-example, at Bloomberg the way we can measure the bytes any
memory-allocating class consumes is by externally passing in a "counting"
polymorphic allocator instead of just letting the class fall through to the
default allocator. With polymorphic allocators, the type of the object does
not change, so it is much easier to do than to try to retrofit STL allocators
into the code to achieve the same thing.

This of course requires buying into the idea of polymorphic allocators as our
STL implements. Lakos et al are pushing this in the committee to become
standard.

See:
[https://bloomberg.github.io/bde/group__bdlma__countingalloca...](https://bloomberg.github.io/bde/group__bdlma__countingallocator.html)

If your code previously did (`bsl` is our `std`):

    
    
        bsl::vector<bsl::string> v;
        v.push_back(...);
    

It simply changes to:

    
    
        bdlma::CountingAllocator ca("Specific vector in my app");
        bsl::vector<bsl::string> v(&ca);
        v.push_back(...);
        ca.print(bsl::cout); // print memory usage

------
jzwinck
That's not a framework but a function being customized. Calling everything a
framework is smelly.

~~~
humanrebar
Fair point, but actual C++ frameworks would benefit from the ideas in this
post. Almost all of them provide a list of ICustomizationPoint interfaces to
derive from. That approach complicates client code more than the framework
authors probably appreciate.

~~~
maxlybbert
I guess we've been using different frameworks. It's certainly true that the
OO-frameworks provide interfaces to derive from. But others have templates to
work with.

In fact, the standard library does both (e.g., customizing streams via
do_get() and do_put(); and providing new iterator types via std::iterator<>).

