3 ms·
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" polymorph
by apaprocki 11y ago
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__countingallocator.html https://bloomberg.github.io/bde/group__bdlma__countingalloca...
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