• Skip to main content
  • Skip to primary sidebar
  • Skip to footer
  • About
  • Life
  • Tech
  • Travel
  • Work
  • Questions
  • Contact

Welcome

.

Can the default C++ std::allocator be supplanted/superseded for 3rd party libraries?

April 10, 2020 by

Questions › Can the default C++ std::allocator be supplanted/superseded for 3rd party libraries?
0
Vote Up
Vote Down
Garmaine asked 3 years ago

My team is working on an application, where we need to track memory usage, and provide statistics on how much memory areas of the program utilize (e.g. N bytes used by uncontrolled STL containers). I need to find a way to identify memory allocated in 3rd party libs from STL containers.

The application makes use of 3rd party libraries that either we don't have access to the source code, or have been directed not to make changes to the source. Some of these libraries use standard STL containers, like std::vector<int>, but they have used (or appear to use, in the case of the closed libs) the default std::allocator. We are targeting Windows, with future work planned for Mac and Linux platforms, using C++17 as much as possible.

I've overridden the malloc and free functions; overridden new, new[], delete and delete[] operators; and created an STLAllocator class derived from std::allocator that is used as the _Alloc template parameter for our use of STL containers. For the libraries that provide hooks to replace the memory allocators, I have done so. When the STL containers in the remaining 3rd partly libs use the default std::allocator, I can see their new and delete calls come through the new and delete overrides, but these appear no different to tracking than a call to new or delete made from main.

I've read many great descriptions of how to declare and use your own std::allocator class, been reminded of the template parameter equality issue when providing different allocators, and made aware of an upcoming solution using std::experimental::pmr::polymorphic_allocator, but I haven't found a definitive answer to my question. Is there a way to supplant the default std::allocator for 3rd party libs that don't provide a hook to override the default std::allocator used by STL containers?

For anyone interested, here is the link that describes the template parameter equality issue; it's also a good overview of std::allocator in general: https://blog.feabhas.com/2019/03/thanks-for-the-memory-allocator/

Are you looking for the answer?
Original Question and Possible Answers can be found on `http://stackoverflow.com`

Question Tags: c++, c++11, c++17, memory-management, stl

Please login or Register to submit your answer




Primary Sidebar

Tags

Advancements best Business strategies commercial convenience economic Finances Cognitive decline Financial growth firm Future Hidden Gems Home hydration Impact Innovations lighting line of work Mental health Must-See New York City office patronage Productivity profession Profitability tips Profit optimization pursuit recreation Revenue enhancement romance sippy cups social station Technological breakthroughs technology toddlers trading transaction Treasures Uncover undertaking Well-being Wonders Work Young onset dementia

Newsletter

Complete the form below, and we'll send you all the latest news.

Footer

Footer Funnies

Who knew that reading the footer could be such a hilarious adventure? As we navigate websites, books, and documents, we often stumble upon the unassuming space at the bottom, only to discover a treasure trove of amusement. In this side-splitting compilation, we present 100 jokes that celebrate the unsung hero of content – the footer. Get ready to chuckle, giggle, and maybe even snort as we dive into the world of footnotes, disclaimers, and hidden comedic gems. Brace yourself for a wild ride through the footer!

Recent

  • Unveiling the Enigma: Almost-Magical Lamp Lights Highway Turns
  • The Impact of Young Onset Dementia on Employment and Finances: Optimizing Post-Diagnostic Approaches
  • 11 Wonders of 2023 Technological Breakthrough – Unveiling the Future
  • Work from Home and Stay Mentally Sane – Achieve Productivity and Well-being
  • Hidden Gems of New York City – Uncover the Must-See Treasures!

Search

Tags

Advancements best Business strategies commercial convenience economic Finances Cognitive decline Financial growth firm Future Hidden Gems Home hydration Impact Innovations lighting line of work Mental health Must-See New York City office patronage Productivity profession Profitability tips Profit optimization pursuit recreation Revenue enhancement romance sippy cups social station Technological breakthroughs technology toddlers trading transaction Treasures Uncover undertaking Well-being Wonders Work Young onset dementia

Copyright © 2023