5

xTaskCreate内存不足分析

 3 years ago
source link: https://www.taterli.com/8124/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

xTaskCreate内存不足分析

使用xTaskCreate创建一个任务,提示errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY,明明configTOTAL_HEAP_SIZE有3000那么多,为什么创建一个2560字节的Heap都会失败呢,那么就分析一下.

首先,我们传进去的其实是usStackDepth,实际还需要和StackType_t相乘,StackType_t取决于平台,像ARM平台默认是uint32_t,也就是传进去2560,实际是10240,还要包含8个字节的xHeapStructSize,即期望10248.

而3000的HEAP_SIZE初始化后也要占用一个 xHeapStruct,所以是2992字节.为了满足他分配,那么需要多大呢?

那当然是最小 8+(usStackDepth*StackType_t +8)+….

所以不能混淆这里分配的大小啊.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK