+ 4

The malloc ()function allocates memory from heap and not from the stack

Why? https://www.sololearn.com/discuss/1945475/?ref=app

28th Aug 2019, 11:56 AM
Anjali Kushwah
Anjali Kushwah - avatar
4 Respostas
+ 3
Thanks for explaining
29th Aug 2019, 11:53 AM
Anjali Kushwah
Anjali Kushwah - avatar
+ 3
Yes, dynamically allocated memory always comes from heap memory.
28th Aug 2019, 12:54 PM
Sonic
Sonic - avatar
0
The stack is controlled directly from the uP with the sp register. This register mark the limit of the stack. Beyond this point the memory is unmanaged but can't be allocated because the stack can grow in any moment. The heap is a bunch of memory, unmanaged but with well defined bounds where the app can use freely. That's why malloc can search for free space in this pool of memory to allocate an arbitrary number of bytes. For more google about the C memory model.
29th Aug 2019, 8:43 PM
Miquel Andreu Fuster Sancho
Miquel Andreu Fuster Sancho - avatar
0
Memory always come from heap memory
30th Aug 2019, 6:26 AM
Täññùprïyå
Täññùprïyå - avatar