From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14311 invoked by alias); 12 Feb 2007 17:42:14 -0000 Received: (qmail 14303 invoked by uid 22791); 12 Feb 2007 17:42:13 -0000 X-Spam-Check-By: sourceware.org Received: from mx2.redhat.com (HELO mx2.redhat.com) (66.187.237.31) by sourceware.org (qpsmtpd/0.31) with ESMTP; Mon, 12 Feb 2007 17:42:08 +0000 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.1/8.13.1) with ESMTP id l1CHg6Vo011937 for ; Mon, 12 Feb 2007 12:42:06 -0500 Received: from zebedee.littlepinkcloud.COM (vpn-14-86.rdu.redhat.com [10.11.14.86]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id l1CHg3TK026452; Mon, 12 Feb 2007 12:42:04 -0500 Received: from littlepinkcloud.COM (localhost.localdomain [127.0.0.1]) by zebedee.littlepinkcloud.COM (8.13.8/8.13.5) with ESMTP id l1CHg16c010614; Mon, 12 Feb 2007 17:42:02 GMT Received: (from aph@localhost) by littlepinkcloud.COM (8.13.8/8.13.5/Submit) id l1CHg1x2010611; Mon, 12 Feb 2007 17:42:01 GMT MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <17872.42729.55690.373110@zebedee.pink> Date: Mon, 12 Feb 2007 19:21:00 -0000 From: Andrew Haley To: "Michael Gong" Cc: Subject: Re: 2 questions In-Reply-To: <00b201c74eca$fb3c6cb0$e56411ac@mwgong> References: <00b201c74eca$fb3c6cb0$e56411ac@mwgong> X-Mailer: VM 7.19 under Emacs 22.0.93.1 X-IsSubscribed: yes Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2007-02/txt/msg00161.txt.bz2 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.