I have a memory intensive application in which the following structs are created at some point.
struct NeighborData {
int flags;
int id;
};
struct Node {
int id;
std::vector<NeighborData> neighbors;
};
struct Graph {
std::vector<Node> nodeList;
};
During the application execution, the Graph
data struct is created. I am trying to estimate the amount of memory used by creating a new Graph
object as below.
total_memory = sizeof(Node) * nodeList.capacity() + aggregate_over_all_nodes(sizeof(NeighborData) * neighbors.capacity()
I have around 3E5 nodes and roughly 2E6 edges in the graph. So its a relatively large data set. During application run, at some point, a method CreateGraph()
gets called. On generating the graph, the memory used by the application appears to increase by almost 150 MB as indicated by the ubuntu system monitor. However, my memory estimates calculated by the method above appear to be much lower and off by more than 100MB. Therefore the two questions below.
- Is my way of estimating memory used by the
Graph
struct correct? Or is there a better way to do this? - If I am certain, that my process does not allocate any new memory after the
CreateGraph()
call, could there by any other reasons for the ubuntu system monitor to show a higher memory usage than what I estimated?