From owner-freebsd-arch@FreeBSD.ORG Mon Mar 27 21:20:54 2006 Return-Path: X-Original-To: freebsd-arch@freebsd.org Delivered-To: freebsd-arch@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 70BA516A422; Mon, 27 Mar 2006 21:20:54 +0000 (UTC) (envelope-from jmg@hydrogen.funkthat.com) Received: from hydrogen.funkthat.com (gate.funkthat.com [69.17.45.168]) by mx1.FreeBSD.org (Postfix) with ESMTP id D510343D46; Mon, 27 Mar 2006 21:20:53 +0000 (GMT) (envelope-from jmg@hydrogen.funkthat.com) Received: from hydrogen.funkthat.com (t8jxfldi4nygv0jp@localhost.funkthat.com [127.0.0.1]) by hydrogen.funkthat.com (8.13.4/8.13.3) with ESMTP id k2RLKrbj008982; Mon, 27 Mar 2006 13:20:53 -0800 (PST) (envelope-from jmg@hydrogen.funkthat.com) Received: (from jmg@localhost) by hydrogen.funkthat.com (8.13.4/8.13.3/Submit) id k2RLKrv1008981; Mon, 27 Mar 2006 13:20:53 -0800 (PST) (envelope-from jmg) Date: Mon, 27 Mar 2006 13:20:52 -0800 From: John-Mark Gurney To: John Baldwin Message-ID: <20060327212052.GK7001@funkthat.com> Mail-Followup-To: John Baldwin , Jason Evans , Vasil Dimov , Robert Watson , freebsd-arch@freebsd.org References: <44247DF1.8000002@FreeBSD.org> <200603271110.02917.jhb@freebsd.org> <44281421.3060401@FreeBSD.org> <200603271520.11381.jhb@freebsd.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200603271520.11381.jhb@freebsd.org> User-Agent: Mutt/1.4.2.1i X-Operating-System: FreeBSD 5.4-RELEASE-p6 i386 X-PGP-Fingerprint: B7 EC EF F8 AE ED A7 31 96 7A 22 B3 D8 56 36 F4 X-Files: The truth is out there X-URL: http://resnet.uoregon.edu/~gurney_j/ X-Resume: http://resnet.uoregon.edu/~gurney_j/resume.html Cc: Vasil Dimov , Robert Watson , Jason Evans , freebsd-arch@freebsd.org Subject: Re: Proposed addition of malloc_size_np() X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: John-Mark Gurney List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 27 Mar 2006 21:20:54 -0000 John Baldwin wrote this message on Mon, Mar 27, 2006 at 15:20 -0500: > On Monday 27 March 2006 11:34, Jason Evans wrote: > > Following is what I've written for the malloc(3) man page: > > ---- > > The malloc_usable_size() function returns the usable size of the > > allocation pointed to by ptr. The return value may be larger than the > > size that was requested during allocation. malloc_usable_size() is not > > intended as a mechanism for in-place realloc(), though it can be abused > > that way; rather it is primarily provided as a tool for introspection > > purposes. Any discrepancy between the requested allocation size and the > > size reported by malloc_usable_size() should not be depended on, since > > such behavior is entirely implementation-dependent. > > ---- > > I would word it stronger: "malloc_usable_size() should not be used as a ^^^^^^ shall > mechanism for in-place realloc(). It is provided solely as a tool for > introspection purposes." should is just a suggestion, it isn't strong enough.. I would also hope that the appropriate test cases are added so that any uses of memory beyond the allocated sizes (and returned by usable_size), are ensured not to have been touched, and that we abort() in cases that someone used memory outside their allocation size... As long as it returns a value that shall not extend the allocation size beyond what was allocated by realloc/malloc/calloc, then it's fine... If it requires a realloc in order to use the additional space, then I'm fine with it... I wouldn't mind an implied behavior that you can do a realloc to malloc_usable_size and it shall not incure a copy.. it'd be useful temp buffers that you grow so you can use the max of the allocated space, instead of waste a bit of unalloced memory... -- John-Mark Gurney Voice: +1 415 225 5579 "All that I will do, has been done, All that I have, has not."