Page 2 of 2

Re:Memory Management -- The Howto (Beginner)

Posted: Wed Mar 30, 2005 3:18 am
by AR
Warrior wrote:The C runtime lib allocates memory fine and the user actually uses malloc when the need arrises that the runtime library cannot anticipate.
Sort of, the Kernel allocates the process image and loads the process image in (.text, .data and .bss).
>Program needs memory
>Calls malloc() in C library
>malloc() determines there isn't any memory left and it needs another page
>Triggers Kernel syscall for AllocatePage()/ExpandHeap()/brk()
>Kernel allocates another page, attaches it to the process and returns
>malloc() fulfils the request and returns to the program.
All calls to malloc are made directly by the programmer.

Re:Memory Management -- The Howto (Beginner)

Posted: Wed Mar 30, 2005 5:43 am
by Warrior
I thought the String library automaticly allocated memory (on windows AFAIK)

Re:Memory Management -- The Howto (Beginner)

Posted: Wed Mar 30, 2005 5:52 am
by AR
Yes the C/C++ Runtime library can malloc internally and return that but those functions still need to be called by the programmer, and the programmer still needs to free()/delete.