How to calculate RAM which the project used?

tony2simmy
Posts: 15
Joined: Fri Jun 09, 2017 3:06 am

How to calculate RAM which the project used?

Postby tony2simmy » Fri Jun 09, 2017 3:37 am

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 ?

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: How to calculate RAM which the project used?

Postby kolban » Fri Jun 09, 2017 4:58 am

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.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: How to calculate RAM which the project used?

Postby WiFive » Fri Jun 09, 2017 6:03 am


tony2simmy
Posts: 15
Joined: Fri Jun 09, 2017 3:06 am

Re: How to calculate RAM which the project used?

Postby tony2simmy » Fri Jun 09, 2017 8:22 am

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.

tony2simmy
Posts: 15
Joined: Fri Jun 09, 2017 3:06 am

Re: How to calculate RAM which the project used?

Postby tony2simmy » Fri Jun 09, 2017 8:23 am

Thank you.

Who is online

Users browsing this forum: No registered users and 88 guests