This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: 2 questions
- From: Andrew Haley <aph at redhat dot com>
- To: "Michael Gong" <mwgong at cs dot utoronto dot ca>
- Cc: <gcc-help at gcc dot gnu dot org>
- Date: Mon, 12 Feb 2007 17:42:01 +0000
- Subject: Re: 2 questions
- References: <00b201c74eca$fb3c6cb0$e56411ac@mwgong>
Michael Gong writes:
> They are not related with gcc. But since gcc's developers are all
> experienced developers and willing to help, I would like to post my
> questions here.
OK, but please don't overdo it.
> 1. when is the local static variable of a function get allocated ? Is it
> during the system startup or when the function is called ?
It's allocated by the compiler, at compile time, long before the
program is even started.
> 2. where does the memory used by malloc() come from ? I know they are
> from heap. So what's the memory of heap come from ?
There are two ways, the old and the new.
The old is via sbrk(2). Ths extends the data segment of a program.
The new is via mmap(2). mmap("/dev/zero", len) allocates zeroed pages
of memory.
The man pages tell you how to use these.
Andrew.