The malloc ()function allocates memory from heap and not from the stack | SoloLearn: Learn to code for FREE!

+4

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

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

8/28/2019 11:56:34 AM

Anjali Kushwah

4 Answers

New Answer

+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