0

Currently I analyze a C++ application and its memory consumption. Checking the memory consumption of the process before and after a certain function call is possible. However, it seems that, for technical reasons or for better efficiency the OS (Linux) assigns not only the required number of bytes but always a few more which can be consumed later by the application. This makes it hard to analyze the memory behavior of the application.

Is there a workaround? Can one switch Linux to a mode where it assigns just the required number of bytes/pages?

5
  • What memory use do you measure (e.g. heap, or stack), and how? Did you use valgrind ? Commented Aug 26, 2013 at 14:02
  • I measure the virtual size of the process. Valgrind has a limited set of number rounding modes thus my application won't run under Valgrind. Commented Aug 26, 2013 at 14:16
  • 1
    See stackoverflow.com/questions/10540845/… the accepted answer. Commented Aug 26, 2013 at 14:17
  • Show some source code and explain much more about your application. valgrind is a very trustful tool, so if your application can't run with it, it is very likely your fault.... Commented Aug 26, 2013 at 14:54
  • @Basile Starynkevitch: It's a limitation of Valgrind. My application uses multiple precision arithmetic. Operations require a rounding mode that exists on real CPUs but is not implemented in Valgrind. Commented Aug 26, 2013 at 15:18

2 Answers 2

1

if you use malloc/new, the allocator will always alloc a little more bytes than you requested , as it needs some room to do its housekeeping, also it may need to align the bytes on pages boundaries. The amount of supplementary bytes allocated is implementation dependent. you can consider to use tools such as gperftools (google) to monitor the memory used.

Sign up to request clarification or add additional context in comments.

Comments

0

I wanted to check a process for memory leeks some years ago.

What I did was the following: I wrote a very small debugger (it is easier than it sounds) that simply set breakpoints to malloc(), free(), mmap(), ... and similar functions (I did that under Windows but under Linux it is simpler - I did it in Linux for another purpose!).

Whenever a breakpoint was reached I logged the function arguments and continued program execution...

By processing the logfile (semi-automated) I could find memory leaks.

Disadvantage: It is not possible to debug the program using another debugger in parallel.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.