From owner-freebsd-arch@FreeBSD.ORG Sat Mar 25 04:51:51 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 B9D0416A400; Sat, 25 Mar 2006 04:51:51 +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 DB32243D46; Sat, 25 Mar 2006 04:51:50 +0000 (GMT) (envelope-from jmg@hydrogen.funkthat.com) Received: from hydrogen.funkthat.com (vby8ne24k4y16qpt@localhost.funkthat.com [127.0.0.1]) by hydrogen.funkthat.com (8.13.3/8.13.3) with ESMTP id k2P4polc015383; Fri, 24 Mar 2006 20:51:50 -0800 (PST) (envelope-from jmg@hydrogen.funkthat.com) Received: (from jmg@localhost) by hydrogen.funkthat.com (8.13.3/8.13.3/Submit) id k2P4pnOl015382; Fri, 24 Mar 2006 20:51:49 -0800 (PST) (envelope-from jmg) Date: Fri, 24 Mar 2006 20:51:49 -0800 From: John-Mark Gurney To: Jason Evans Message-ID: <20060325045149.GA7001@funkthat.com> Mail-Followup-To: Jason Evans , freebsd-arch@FreeBSD.org References: <44247DF1.8000002@FreeBSD.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <44247DF1.8000002@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: 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: Sat, 25 Mar 2006 04:51:51 -0000 Jason Evans wrote this message on Fri, Mar 24, 2006 at 15:17 -0800: > === Proposal === > Add malloc_size_np() to libc, and provide the prototype in malloc_np.h: > > size_t > malloc_size_np(const void *ptr); > > This function would return the usable size of the allocation pointed to > by ptr, which is always greater than or equal to the size that was > specified in the call to malloc(), calloc(), posix_memalign(), or > realloc(), regardless of allocator implementation. It is up to the > implementation whether the value returned by malloc_size_np() differs > from the size specified during allocation, but the return value must be > consistent across multiple calls for the same allocation. a) the idea of using memory beyond what you've allocated is bad... b) it should return the maximum size you can realloc to w/o a copy of the memory... and then the way you use the extra memory is to call realloc on the buffer to the value returned by malloc_size_np.. My vote is to never let allocations go outside their area even if they could... It'll just make new programmers lazy, and ready to break something... -- John-Mark Gurney Voice: +1 415 225 5579 "All that I will do, has been done, All that I have, has not."