Heap usage don't update when use vPortFree.

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Heap usage don't update when use vPortFree.

跳至解决方案
2,380 次查看
andréluis
Contributor II

Hello, i'm using the MIMXRT1060-EVK. In my project i'm using freeRtos and lwip with the heap_3.c. When i use vPortFree, the value of the heap don't update. There's something I can do to update heap usage?

标记 (1)
0 项奖励
回复
1 解答
2,032 次查看
DanielRuvalcaba
NXP TechSupport
NXP TechSupport

Hi @andréluis,

 

Heap3 scheme only wraps the standard C library malloc() and free() functions to provide thread safety. In this case, when you use pvPortMalloc(), the function will use malloc() to allocate memory.

It's not like vPortFree() isn't working. It is, but you will not see the change in the Heap and Stack Usage option because as per my understanding, free() doesn't delete nor clear the memory, it only marks the space as available for future malloc() allocations.

You can see this by yourself by allocating memory using pvPortMalloc(), then free it with vPortFree(). Then immediately allocate the same amount of memory, you will see that the Heap and Stack Usage will increase only once and not twice.

For more information regarding this, I would recommend you take a look to the FreeRTOS documentation.

 

I hope this helps.

Regards,

Daniel.

在原帖中查看解决方案

0 项奖励
回复
8 回复数
2,366 次查看
DanielRuvalcaba
NXP TechSupport
NXP TechSupport

Hi,

 

Could you please help me with the following infromation?

 

What SDK version are you using?

Are you trying a SDK example?

How you are making and verifying the heap change?

If I'm understanding correct you would like to use heap 3, but in your project the heap in use in another one, am I right?

 

Regards,

Daniel.

0 项奖励
回复
2,307 次查看
andréluis
Contributor II

Hi Daniel
What SDK version are you using?
I'm using the SDK 2.14 of MIMXRT1060-EVK

Are you trying a SDK example?
Yes. I'm working with evkbmimxrt1060_lwip_ipv4_ipv6_echo_freertos.

How you are making and verifying the heap change?

I attach an image showing how i making the verify of the heap.

If I'm understanding correct you would like to use heap 3, but in your project the heap in use in another one, am I right?

In my project it's using heap_3.c.

0 项奖励
回复
2,298 次查看
DanielRuvalcaba
NXP TechSupport
NXP TechSupport

Thanks for the reply.

I'm sorry for the misunderstanding, I thought you were trying to change the FreeRTOS Heap implementation.

Is there a specific path to get this behavior? If that's the case, could you please tell me how you are running the example so I can try to replicate it on my side?

 

Regards,

Daniel.

0 项奖励
回复
2,286 次查看
andréluis
Contributor II

Hello Daniel, in the picture attach i put a breakpoint when my application call the vPortFree. In my application, i send to him some blocks, like function blocks of PLC, and the value of my heap increase because the blocks. But, when i remove the blocks from my application, the value of the heap don't decreases, showing the same value. In the pictures i show the value before the dowload of the application, the process of download an application, update the value of the heap, download an empty application and the value of the heap don't change. 

0 项奖励
回复
2,246 次查看
DanielRuvalcaba
NXP TechSupport
NXP TechSupport

In other words, in the evkbmimxrt1060_lwip_ipv4_ipv6_echo_freertos SDK example, when you use vPortFree, you don’t see a change in the heap usage. The heap stays the same, am I correct?

 

Regards,

Daniel.

0 项奖励
回复
2,180 次查看
andréluis
Contributor II

Hello Daniel. Yes. This is the problem. I use vPortFree and the heap usage don't change. 

0 项奖励
回复
2,033 次查看
DanielRuvalcaba
NXP TechSupport
NXP TechSupport

Hi @andréluis,

 

Heap3 scheme only wraps the standard C library malloc() and free() functions to provide thread safety. In this case, when you use pvPortMalloc(), the function will use malloc() to allocate memory.

It's not like vPortFree() isn't working. It is, but you will not see the change in the Heap and Stack Usage option because as per my understanding, free() doesn't delete nor clear the memory, it only marks the space as available for future malloc() allocations.

You can see this by yourself by allocating memory using pvPortMalloc(), then free it with vPortFree(). Then immediately allocate the same amount of memory, you will see that the Heap and Stack Usage will increase only once and not twice.

For more information regarding this, I would recommend you take a look to the FreeRTOS documentation.

 

I hope this helps.

Regards,

Daniel.

0 项奖励
回复
1,658 次查看
andréluis
Contributor II
Hi Daniel, in my application, i need to calculate how much a block consume when i select it in the program. That's why i need to use the free, because if i remove a block, i need to calculate how much RAM became free. That's a way to change the free() function?
0 项奖励
回复