Note that there are some explanatory texts on larger screens.

plurals
  1. POAccurately Calculating the Memory used by a C++ Programming
    primarykey
    data
    text
    <p>A program I am writing for work needs to keep track of the memory used by itself. But it can't monitor its memory usage as a whole, I need it to monitor each object in the program and how much memory that object is using, that way it can then tell that object to cut back on memory usage if it using above a certain capacity. The part that monitors memory usage holds a pointer to all created objects and keeps track of their memory usage by calling a method on that object that returns the size of the object.</p> <p>The problem I'm having is that I cannot accurately calculate the size of the memory used. It doesn't matter if my calculation are off by a little bit but I'm getting big difference. The size that my program calculates varies (depending on which actions the program performs) between 1/2 to 2/3 of the actual memory usage of the program. For example a program that used 3.35gb of ram was calculated to only be using 2.16gb.</p> <p>The current way I calculate the size of an object is by adding sizeof(*this) to the length of any vectors or arrays in the object multiplied by the sizeof the elements in the vector/array.</p> <p>Is there something wrong with the way I'm calculating the memory used? Or is there just something else I'm not taking into account? If anyone knows of a program that you can analyse memory usage by different aspects of a program that would also be very helpful, that way I can track down where all this extra memory is coming from (preferably one that can run on Linux without GUI as I'm using Ubuntu server, but also have a windows machine I can use).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload