Where does xQueueCreate get its memory from?

CollinK
Posts: 18
Joined: Mon Apr 16, 2018 11:38 pm

Where does xQueueCreate get its memory from?

Postby CollinK » Wed Aug 01, 2018 1:10 am

It's a rather stupid sounding question and seems straight forward... You'd think a queue would be allocate on the heap. But, it seems not because I've found that creating tasks and queues seems to run me out of memory but when I trim it down just a bit (so that the code doesn't instantly ABORT() on start up) I find that the heap still has like 180K free! So, where are task stacks and queues allocated? And, how can I figure out how much of that RAM I've still got left?

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: Where does xQueueCreate get its memory from?

Postby ESP_Angus » Wed Aug 01, 2018 1:19 am

If you call xQueueCreate() or xTaskCreate() or xTaskCreatePinnedToCore(), the memory for the queue contents or the task stack is allocated from heap.

If you have external SPI RAM enabled, the tasks have to be allocated from internal memory but the queues can be allocated anywhere.

There are also "static versions" of these functions, xQueueCreateStatic() and xTaskCreateStatic, etc. which allow you to provide the buffers, so they can be statically allocated. But it doesn't like that's in use here.

There is some heap memory which is not available during the early boot process (it's reserved for stacks used by startup code). However by the time app_main() is running, this memory will be available on the heap.

Can you give some specifics about what code caused you to run out of memory, and exactly what errors were seen?

chegewara
Posts: 2362
Joined: Wed Jun 14, 2017 9:00 pm

Re: Where does xQueueCreate get its memory from?

Postby chegewara » Wed Aug 01, 2018 1:49 am

http://esp-idf.readthedocs.io/en/latest ... skHandle_t
I cant find this function in docs but i am using it:

Code: Select all

ESP_LOGW(TAG, "RAM left %d", esp_get_free_heap_size());

Who is online

Users browsing this forum: Bing [Bot] and 88 guests