2016-08-16 12:56 AM
Hi all,
Is there a way to calculate the size of used RAM at running time. So that I can calculate how much RAM is still available for use. Actually I have to show used RAM in percentage to my product customer.Solved! Go to Solution.
2016-08-16 02:51 AM
To answer this questions it is necessary to give a clear definition about the words ''ram'' and ''used''.
Ram usually consist of heap and stack memory. If you are using some operating system it should be possible to calculate how much stack that was allocated for each process, however that will lead us to the question above of what ''used'' really means. When it comes to heap it will get a little more difficult. If you have control over the malloc and free functions is could be possible to keep some counter here tracking the allocated memory (given that malloc is always used to allocate memory). To count the stack usage you could also just subtract the stack pointer from the start of the stack (probably found in link script).2016-08-16 02:51 AM
To answer this questions it is necessary to give a clear definition about the words ''ram'' and ''used''.
Ram usually consist of heap and stack memory. If you are using some operating system it should be possible to calculate how much stack that was allocated for each process, however that will lead us to the question above of what ''used'' really means. When it comes to heap it will get a little more difficult. If you have control over the malloc and free functions is could be possible to keep some counter here tracking the allocated memory (given that malloc is always used to allocate memory). To count the stack usage you could also just subtract the stack pointer from the start of the stack (probably found in link script).2016-08-16 05:57 AM
There are usually linker symbols you can apply or use to determine the initial RAM (statics) usage. You can walk the heap via the linked list describing the arena there (dynamic), and you can measure the maximal stack depth (local/auto).