Memory usage of xTaskCreate() within a task

zliudr
Posts: 66
Joined: Thu Oct 03, 2019 5:15 am

Memory usage of xTaskCreate() within a task

Postby zliudr » Mon Nov 25, 2019 4:09 am

If I allocated x amount of stack for task 1, then task 1 calls xTaskCreate() to create task 2, giving it y amount of stack, then would the y amount come out of the x amount or not? My hope is not. When a task ends, the memory is released, correct? Thanks.

ESP_Sprite
Posts: 2908
Joined: Thu Nov 26, 2015 4:08 am

Re: Memory usage of xTaskCreate() within a task

Postby ESP_Sprite » Mon Nov 25, 2019 9:35 am

No. Task memory is allocated using malloc() (well, technically it's a version of malloc that only allocates from internal memory) and freed using free() when vTaskDelete() is called and the idle task gets the chance to clean up the task. In other words: The stack of the calling task is unaffected, and the memory will be returned to the heap after a task is cleaned up.

zliudr
Posts: 66
Joined: Thu Oct 03, 2019 5:15 am

Re: Memory usage of xTaskCreate() within a task

Postby zliudr » Mon Nov 25, 2019 1:21 pm

Thanks. Should the task call vTaskDelete itself before returning?
Regarding internal memory, is wrover psram considered internal? What memory is not internal?

ESP_Dazz
Posts: 147
Joined: Fri Jun 02, 2017 6:50 am

Re: Memory usage of xTaskCreate() within a task

Postby ESP_Dazz » Mon Nov 25, 2019 3:07 pm

  • vTaskDelete() itself does not return the memory when deleting a current running task. The memory is instead free in the IDLE task.
  • SPI RAM is not internal

zliudr
Posts: 66
Joined: Thu Oct 03, 2019 5:15 am

Re: Memory usage of xTaskCreate() within a task

Postby zliudr » Tue Nov 26, 2019 4:45 am

Thanks for clarifying. Then what does the psram do in wrover modules? Hash space other than task stacks, like allocating large memory blocks? Could you point me to some documentation on different ESP32 memories and psram?

ESP_Sprite
Posts: 2908
Joined: Thu Nov 26, 2015 4:08 am

Re: Memory usage of xTaskCreate() within a task

Postby ESP_Sprite » Wed Nov 27, 2019 7:48 am

Yes, exactly. You retrieve blocks of memory using malloc() and friends, so it gets used anywhere where large blocks of memory are allocated this way.

zliudr
Posts: 66
Joined: Thu Oct 03, 2019 5:15 am

Re: Memory usage of xTaskCreate() within a task

Postby zliudr » Sun Dec 01, 2019 2:20 am

So If I enable psram in menuconfig and compile my code, then psram gets automatically used whenever malloc() runs? Thanks.

Who is online

Users browsing this forum: axellin, Google [Bot], MSN [Bot] and 19 guests