Page 1 of 1

How to calculate RAM which the project used?

Posted: Fri Jun 09, 2017 3:37 am
by tony2simmy
I am a freshman in ESP platform. Now,i have a task which is to get the total of used RAM in examples .Do some people know it ?

Re: How to calculate RAM which the project used?

Posted: Fri Jun 09, 2017 4:58 am
by kolban
There is an ESP-IDF API called esp_get_free_heap_size() which returns the current number of bytes available on the heap for your application to use. When we talk about RAM, we usually think of heap from which can be carved malloc() storage. Another type of RAM usage is "stack" which is per task. The amount of storage allocated to a task is specified when the task is created and is under application control. To the best of my knowledge, when a new task is created, the storage for the stack is itself carved from the heap.

Of the 512K RAM available on an ESP32, about 200K is available to the heap when you app starts. Also remember that some system functions such as WiFi, sockets and Bluetooth connections will also eat into your heap allocation.

You can log the output of esp_get_free_heap_size() at the start of your application and when it it has reached its operational steady state to determine how much your own application has used.

Re: How to calculate RAM which the project used?

Posted: Fri Jun 09, 2017 6:03 am
by WiFive

Re: How to calculate RAM which the project used?

Posted: Fri Jun 09, 2017 8:22 am
by tony2simmy
kolban wrote:There is an ESP-IDF API called esp_get_free_heap_size() which returns the current number of bytes available on the heap for your application to use. When we talk about RAM, we usually think of heap from which can be carved malloc() storage. Another type of RAM usage is "stack" which is per task. The amount of storage allocated to a task is specified when the task is created and is under application control. To the best of my knowledge, when a new task is created, the storage for the stack is itself carved from the heap.

Of the 512K RAM available on an ESP32, about 200K is available to the heap when you app starts. Also remember that some system functions such as WiFi, sockets and Bluetooth connections will also eat into your heap allocation.

You can log the output of esp_get_free_heap_size() at the start of your application and when it it has reached its operational steady state to determine how much your own application has used.
Thank you very much, it is helpful to me.

Re: How to calculate RAM which the project used?

Posted: Fri Jun 09, 2017 8:23 am
by tony2simmy
Thank you.