Thomas W.
Thomas W.

Reputation: 2224

Determine memory usage of an std::map/std::set at runtime

Is it possible to determine the real memory usage of an std::map/std::set (of intrinsic data types) at runtime? I made some memory studies and it seems that this highly depends on the STL implementation and on the system which is used (due to memory padding of the underlying structs). I would like to monitor the memory usage of these data types at runtime, without running a debugger/memory profiler. Is there any way to do this?

Upvotes: 0

Views: 548

Answers (1)

Grzegorz Herman
Grzegorz Herman

Reputation: 1915

Implement a custom allocator which will count the memory used, and provide that to the constructor of your map/set.

Upvotes: 9

Related Questions