+ 27

Is there a way to get the used memory of the current running program while the program is running?

12th Aug 2019, 6:37 PM
Worm
Worm - avatar
10 Answers
+ 28
GAWEN STEASY but I need the used memory of my program and then the execution time doesn't help 😉
13th Aug 2019, 11:55 AM
Worm
Worm - avatar
+ 25
GAWEN STEASY that helps to get the time the program used to execute the code between two points. I want to get the used memory of the hole program without using calloc() for each used variable. But maybe I have to use calloc() this way.. đŸ€”
12th Aug 2019, 6:57 PM
Worm
Worm - avatar
+ 20
BootInk I think that is a possible solution to realize that. But if you are using array lists you have to document the number of elements of that list. I'll try a solution and when I'm ready I'll post it here.
19th Aug 2019, 8:34 PM
Worm
Worm - avatar
+ 16
BootInk thanks!
25th Aug 2019, 5:34 PM
Worm
Worm - avatar
12th Aug 2019, 6:44 PM
GAWEN STEASY
GAWEN STEASY - avatar
+ 7
Worm std::chrono is used for getting execution time, you can see that in the link of the thread.
12th Aug 2019, 7:02 PM
GAWEN STEASY
GAWEN STEASY - avatar
+ 2
The more number of times you use that specific pointer; each time it is updated to a new value. Just make sure you do all your modifications before free(), After which the used up memory is actually released and there is no particular scope to refer to it thereby
17th Aug 2019, 5:39 PM
Aditya
Aditya - avatar
+ 2
I may be wrong, and this might be entirely unrelated to your question, but couldn't you implement a container (queue, list, etc) containing the pointers to all the variables, and update that whenever a new variable/pointer is created (or destroyed)? Then, when you want to retrieve the amount of memory at runtime, you could call a function that iterates through the container, de-referencing and calling the sizeof() function on each element, adding the result to an accumulator variable. If you're wanting a library function on this, I'm afraid I can't help on that.
19th Aug 2019, 1:40 PM
BootInk
BootInk - avatar
+ 2
Try studying the std:list object here: http://www.cplusplus.com/reference/list/list/list/. Lists do require a starting size for each list object you make, but as you add new elements to the objects, they can dynamically change their size. However, each object is still restricted to their type, whether they are builtins, or user defined classes or structs. If you decide to use 'new' to dynamically allocate memory, for example, it would have to be the same pointer type as those already found within the list. So, you can't put a int in a float list, or you can't put a user defined object within a builtin list. Hope this helps somewhat. I've decided to study the std library for C++, and found this along the way.
24th Aug 2019, 12:41 AM
BootInk
BootInk - avatar