I have a boost bimap
#include <iostream>
#include <utility>
#include <boost/bimap.hpp>
#include <boost/bimap/set_of.hpp>
#include <boost/bimap/multiset_of.hpp>
namespace bimaps = boost::bimaps;
typedef boost::bimap<bimaps::set_of<unsigned long long int>,
bimaps::multiset_of<unsigned long long int > > bimap_reference;
typedef bimap_reference::value_type position;
bimap_reference numbers;
int main()
{
numbers.insert(position(12345689, 1000000000));
numbers.insert(position(23456789, 8000000000));
return 0;
}
I have about 180000000 entries. Theoretically it should take ~2.7GB of space (180000000*8*2 = 2880000000 bytes = 2880000000/ 1024*1024*1024 = ~2.7GB ). Now I want to find the actual space taken by boost bimap
, how can I do that.
Like the comments under your question mention, you can overload the
new
anddelete
operators to track memory allocations and deallocations. The example under the Global replacements section of this article shows a very simple example:The only problem with this example that you cannot determine how much memory is freed. To solve this issue, check out the accepted answer of How to track memory allocations in C++ (especially new/delete) question.
The example inside the mentioned answer uses
std::map
with custom allocator to store the addresses and sizes of allocated memory blocks. Inside thedelete
operator overload it removes elements with specified addresses. With almost no modifications it can be used to your requirements:Live Demo