dynamic memory allocation doubts

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

dynamic memory allocation doubts

ソリューションへジャンプ
495件の閲覧回数
vignesh3
Contributor II

Hi NXP community,

HEAP_SIZE = DEFINED(__heap_size__) ? __heap_size__ : 0x00001000;

This heap memory allocation is defined in SRAM area using linker script.

Can anyone tell me the above mentioned heap is used by standard library or not, Like malloc, calloc and free?  

0 件の賞賛
返信
1 解決策
481件の閲覧回数
gaurav_sharma
NXP Employee
NXP Employee

@vignesh3 , yes the C runtime will use this heap region to serve the dynamically allocated memory requests. the heap is initialized in the startup code. The linker defines the heap size with the variable named HEAP_SIZE.  

malloc uses _sbrk function. 
_sbrk  uses the variables such as __heap_limit defined in the linker. That's how the dynamically allocated memory is defined and used. 

Hope this helps!

元の投稿で解決策を見る

0 件の賞賛
返信
3 返答(返信)
482件の閲覧回数
gaurav_sharma
NXP Employee
NXP Employee

@vignesh3 , yes the C runtime will use this heap region to serve the dynamically allocated memory requests. the heap is initialized in the startup code. The linker defines the heap size with the variable named HEAP_SIZE.  

malloc uses _sbrk function. 
_sbrk  uses the variables such as __heap_limit defined in the linker. That's how the dynamically allocated memory is defined and used. 

Hope this helps!

0 件の賞賛
返信
226件の閲覧回数
vignesh3
Contributor II

Hi @gaurav_sharma ,

_sbrk is for allocating the memory right?

If it is like this where can it get free?

Thanks for the reply.

0 件の賞賛
返信
212件の閲覧回数
gaurav_sharma
NXP Employee
NXP Employee

@vignesh3 , yes _sbrk is a function used by malloc() to increment 'heap_end' and returns a pointer. So it allocates memory in that sense.
Using the function 'free()', the memory gets freed per se. This means that this function marks this memory as available for re-use. 

0 件の賞賛
返信