Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8987373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:46:29+00:00 2026-06-15T21:46:29+00:00

A program I am writing for work needs to keep track of the memory

  • 0

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.

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.

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.

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).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T21:46:31+00:00Added an answer on June 15, 2026 at 9:46 pm

    Is there something wrong with the way I’m calculating the memory used?

    Yes. First of all, the size of the memory consumed by your program may not be entirely used at any one point. For instance, after a vector resizes, the old memory block may be returned to the system. Or it may be held on to by the heap for the next time someone requests a memory block of the same size.

    Also, do keep in mind that any libraries you are using (E.g. OS APIs) allocate memory, and those things aren’t free.

    Also keep in mind that there is additional overhead imposed by the heap manager for each memory allocation; usually on the order of a pointer or two, per allocation.

    If you want to track what is using memory in your application, use a real memory profiler for that. If you want to dynamically scale how much memory your program allocates in the first place, use a profiler to figure out the average size taken up by one of the objects you are dealing with, and then limit by number of objects rather than memory size.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a JAVA program for work that at some point needs to
I am writing a program that needs to be able to work with text
I'm writing a program which needs to traverse a set of directories. Tried to
I'm writing a program that among other things needs to download a file given
I'm writing a program that, among other things, needs to display a context menu
I'm writing a program for my workplace and because we work on computers damaged
I'm writing a program in C that needs to do some fast math calculations.
I am writing a program that needs a list of English words as a
I am writing a program in which it needs to determine the range of
I'm writing a program that needs to be able to kill certain processes. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.