+ 4
The malloc ()function allocates memory from heap and not from the stack
4 Respostas
+ 3
Thanks for explaining
+ 3
Yes, dynamically allocated memory always comes from heap memory.
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.
0
Memory always come from heap memory