From owner-freebsd-questions@FreeBSD.ORG Mon Oct 6 09:42:30 2003 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 8F75F16A4BF for ; Mon, 6 Oct 2003 09:42:30 -0700 (PDT) Received: from web21104.mail.yahoo.com (web21104.mail.yahoo.com [216.136.227.106]) by mx1.FreeBSD.org (Postfix) with SMTP id 71D6543FF2 for ; Mon, 6 Oct 2003 09:42:29 -0700 (PDT) (envelope-from materribile@yahoo.com) Message-ID: <20031006164229.55196.qmail@web21104.mail.yahoo.com> Received: from [24.228.74.10] by web21104.mail.yahoo.com via HTTP; Mon, 06 Oct 2003 09:42:28 PDT Date: Mon, 6 Oct 2003 09:42:28 -0700 (PDT) From: Mark Terribile To: freebsd-questions@freebsd.org In-Reply-To: <20031006120313.D41CE16A4F1@hub.freebsd.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii cc: James Jacobsen Subject: Re: malloc() behavior (was: Pointer please) X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 06 Oct 2003 16:42:30 -0000 >>>> It does not matter what freebsd does, C does >>>> not require that malloc initialize space >>>> according to Kernighan and Ritchie. >> ... What's really bad, is that freebsd could >> potentally change there behavor down the line. >> Its probably dictated by the way kernel dezined, >. meaning they may do whats the cheapist. > There's nothing bad about it. FreeBSD follows > the standards. ... There's a distinction here which has been mentioned and perhaps lost. The kernel does provide programs with zero'd memory, but unless you are doing system calls (man section 2) directly you are not seeing what the kernel does. You are seeing what the C language runtime code (malloc(), calloc(), free(), etc.) does. They use the system calls, but the semantics are the semantics that the authors of the runtime implemented. And since the runtime is provided with the compiler (typically gcc) it's only a function of convenience when the language definition says it may be. The kernel's pool of zero'd buffer pages is used to provide zero'd memory on demand while doing the work when the CPU may be free. Sort of like washing the dishes before you need them. The kernel C code does not use the C runtime, except possibly for some very low-level routines that might be needed to implement extended precision, do stack frame management, or other very-low-level stuff. And there's precious little needed on newer processors. Mark Terribile __________________________________ Do you Yahoo!? The New Yahoo! Shopping - with improved product search http://shopping.yahoo.com