0

I have a program that runs a specific task over several files, so effectively it has a structure as follow:

std::vector<string> fileList=getFileList();
for(int i=0;i<fileList.size();i++)
{
       processFile(fileList[i]);
}

I am worried that there is a small memory leak in processFile function (this is relatively complex function which calls several other functions and uses several classes).

To check if I really have a memory leak in this function, like to measure the amount of memory that my application uses before and after the call to processFile and run it over a very large set of data and see how memory usage changes during processing.

Is there any way that I can measure the amount of memory that my application is using inside that application?

In the same way, can I find the amount of memory that each part of my application is using during run time?

mans
  • 17,104
  • 45
  • 172
  • 321

2 Answers2

0

if you want measure how much memory is using via above code at runtime u must calculate this:

(# of element in fileList) * sizeof(string) + size of files in fileList

but if you want get all of your process memory usage in windows at runtime you can call GetProcessMemoryInfo API in your program and pass your process handle(GetCurrentProcess() API) to it,sample usage of this API:

https://msdn.microsoft.com/en-us/library/ms682050.aspx

see complete response to your question via this link:

How to determine CPU and memory consumption from inside a process?

Community
  • 1
  • 1
0

A common solution to detecting memory leaks and monitoring memory usage would be to run your program with valgrind.

abort
  • 191
  • 9