From owner-freebsd-hackers@FreeBSD.ORG Mon Jun 13 21:16:57 2005 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 9EDA216A41C for ; Mon, 13 Jun 2005 21:16:57 +0000 (GMT) (envelope-from des@des.no) Received: from tim.des.no (tim.des.no [194.63.250.121]) by mx1.FreeBSD.org (Postfix) with ESMTP id 3F78A43D48 for ; Mon, 13 Jun 2005 21:16:57 +0000 (GMT) (envelope-from des@des.no) Received: from tim.des.no (localhost [127.0.0.1]) by spam.des.no (Postfix) with ESMTP id 26F7660F7; Mon, 13 Jun 2005 23:16:50 +0200 (CEST) Received: from xps.des.no (des.no [80.203.228.37]) by tim.des.no (Postfix) with ESMTP id 0A68E60F5; Mon, 13 Jun 2005 23:16:50 +0200 (CEST) Received: by xps.des.no (Postfix, from userid 1001) id EED2233C49; Mon, 13 Jun 2005 23:16:49 +0200 (CEST) To: Mike Hunter References: <20050610224058.GA11336@malcolm.berkeley.edu> <86vf4lb110.fsf@xps.des.no> <20050613193150.GA75218@malcolm.berkeley.edu> From: des@des.no (=?iso-8859-1?q?Dag-Erling_Sm=F8rgrav?=) Date: Mon, 13 Jun 2005 23:16:49 +0200 In-Reply-To: <20050613193150.GA75218@malcolm.berkeley.edu> (Mike Hunter's message of "Mon, 13 Jun 2005 12:31:50 -0700") Message-ID: <868y1eufcu.fsf@xps.des.no> User-Agent: Gnus/5.110002 (No Gnus v0.2) Emacs/21.3 (berkeley-unix) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Spam-Learn: ham X-Spam-Score: -5.2/5.0 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on tim.des.no Cc: freebsd-hackers@freebsd.org Subject: Re: unitialized memory is all zeros...why not garbage instead? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 13 Jun 2005 21:16:57 -0000 Mike Hunter writes: > Is the pre-zeroing of malloc'd memory documented somewhere? By my reading > of the malloc manapge... malloc() does not pre-zero memory, but it hands you memory which has been pre-zeroed by the kernel unless you've used it before. Your test program makes only one malloc() call, so you get memory that has never been used before. > ...it seems like it's saying that malloc (as opposed to calloc) is NOT > pre-zeroed. Is there a different document I should be reading? No, but nowhere in the standard does it say that memory allocated with malloc() must contain non-zero garbage. If that is what you want, though, read the TUNING section in the malloc(3) man page. DES --=20 Dag-Erling Sm=F8rgrav - des@des.no