IMXRT1170 dynamic memory allocation

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

IMXRT1170 dynamic memory allocation

683 Views
ahmedhrabi
Contributor IV

Hello All,

I'am testing dynamic memory usage on imxrt1176 on baremetal. When using standard C malloc() then free() functions, the allocated space is not released with the free function. The heap do not decrease:

MallocFreeImxrt.PNG

Regards, 

Ahmed.

0 Kudos
Reply
2 Replies

664 Views
jeremyzhou
NXP Employee
NXP Employee

Hi @ahmedhrabi ,

There's the feedback from the AE team.

The Usage of 'Heap and Stack Usage' displays the maximum value which allocated, the usage value will update when the current allocated space larger than the previous allocated space, not update when the current allocated space smaller than the previous allocated space. In fact, the allocated space is released with the free function.

Some test results is below:

(1) array = (int*)malloc(50* sizeof(int));   the Usage displays 5.18%.

jeremyzhou_0-1659410717183.png

 

(2) array = (int*)malloc(200* sizeof(int)); the Usage will update as 19.82%.
jeremyzhou_1-1659410717330.png

 

(3) array = (int*)malloc(50* sizeof(int)); the Usage will remain as 19.82%, which is consistent with the applied maximum space before.
jeremyzhou_2-1659410717038.png

 

Have a great day,
TIC

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos
Reply

676 Views
jeremyzhou
NXP Employee
NXP Employee

Hi,
Thank you for your interest in NXP Semiconductor products and for the opportunity to serve you.
In basic, I replicate the phenomenon you mentioned, further, I use the below code to find that MCUXpreso IDE can display the increasing heap usage.
I'll report the phenomenon to the IDE team for further checking soon later.

    for(uint32_t i = 1; i < 5; i++)
    {
        int *array = (int*)malloc(32*sizeof(int)*i);
        if (NULL == array)
        {
        	return -1;
        }
        free(array);

        array = NULL;
    }


Have a great day,
TIC

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos
Reply