I am developing a Graph-class, based on boost-graph-library.
A Graph-object contains a boost-graph, so to say an adjacency_list, and a map.
When monitoring the total memory usage of my program, it consumes quite a lot (checked with pmap).
Now, I would like to know, how much of the memory is exactly consumed by a filled object of this Graph-class? With filled I mean when the adjacency_list is full of vertices and edges.
I found out, that using sizeof() doesn’t bring me far. Using valgrind is also not an alternative as there is quite some memory allocation done previously and this makes the usage of valgrind impractical for this purpose. I’m also not interested in what other parts of the program cost in memory, I want to focus on one single object.
Thank you.
I have never used
adjacency_listso this is just an idea which although works with STL containers.So using adjacency_list says
BGL uses containers from the STL such as std::vector, std::list, and std::set to represent the set of vertices and the adjacency structure. OK, then you just have to give your adjacent list std::vector, std::list, and std::set which have their own allocator type. Adding your own allocator to STL containers is an easy task. Having done all this you just have to get from your allocators the size of memory that has been allocated while filling the adjacency_list.So the idea is to build the adjacent list out of STL containers (which seems possible after a quick look at the BGL documentaiton) which have own allocator types.
Update 1
Actually you haven’t told why you need to know how much bytes your graph consumes. If you just need to get this number only once you probably have to write you program with and without filling the graph. Then run for example
UNIX95= ps -u $USER -o vsz,argsand find out the difference. Roughly you will get the size of you graph.If you need to get this values regularly in your application and if you are not able to implement the whole solution using allocators you need to start with a few small steps.
C++ Standard Allocator, An Introduction and Implementation
Allocators(STL)
Customizing the Adjacency List Storage
By the way if you don’t want to reinvent the C++ allocator you can just use something like that: