From owner-freebsd-current@FreeBSD.ORG Sun Dec 1 10:55:15 2013 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 166E529B; Sun, 1 Dec 2013 10:55:15 +0000 (UTC) Received: from mail-bk0-x22b.google.com (mail-bk0-x22b.google.com [IPv6:2a00:1450:4008:c01::22b]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 732A21E0E; Sun, 1 Dec 2013 10:55:14 +0000 (UTC) Received: by mail-bk0-f43.google.com with SMTP id mz12so4933459bkb.30 for ; Sun, 01 Dec 2013 02:55:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=PRr8lC3CaqJBiaDO9zu++rjM6jcUTjaqO7r1lDNxD5E=; b=GEq47MbAYZC6nNyCwk3Ku61aTbfFHy8FBVw7dnYY9sN5zDzQAjHnNHbgNfv5q8uABe Ibxk7OtcS+6jICfFpphQ3e49iNbr37OQVI/uwvnzBq+eq8T69fFd0i89kzwJ5JWi055V wz5/elIqd7OGvBjBI0yqMLFEgod0TF0PKPBLpr786iXYuJFm9UP1urC0RoycR88US/pw ocClBuQ9Cd7KL070oJA+sh5Jt+tApDo6UVfDzkI20zVoFrtb5QtglpPi/8FnbgWYQWbT 3iabl57oF+LoK4z1QGx93wlGGsPuBDbuo8S24VdI7+92g+DEEnxp5Q0K7SWJ2ynhPUiT EZGg== MIME-Version: 1.0 X-Received: by 10.204.227.198 with SMTP id jb6mr130118bkb.69.1385895312690; Sun, 01 Dec 2013 02:55:12 -0800 (PST) Received: by 10.204.163.129 with HTTP; Sun, 1 Dec 2013 02:55:12 -0800 (PST) In-Reply-To: <529AA73A.9@gmx.com> References: <20131201022002.GE55638@funkthat.com> <529AA73A.9@gmx.com> Date: Sun, 1 Dec 2013 11:55:12 +0100 Message-ID: Subject: Re: [RFC] how to get the size of a malloc(9) block ? From: Daniel Nebdal To: dt71@gmx.com Content-Type: text/plain; charset=ISO-8859-1 X-Content-Filtered-By: Mailman/MimeDel 2.1.16 Cc: jb , Adrian Chadd , freebsd-current , Luigi Rizzo X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 01 Dec 2013 10:55:15 -0000 On Sun, Dec 1, 2013 at 4:04 AM, wrote: > John-Mark Gurney wrote, On 12/01/2013 03:20: > > Either it happens rarely, and always doing a realloc won't hurt >> performance, or it happens often, and then you should be using a larger >> buffer in the first place.. >> > > What if a size-elastic implementation of a dynamic data structure would be > able to adjust to the malloc implementation, such as agreeing to allocate > regions of size (2^k - 8)? Much like the use of getpagesize() (yes, I know > it's not part of a technical standard). > > That could alternatively be solved by having an "if I ask for N bytes right now, how large would the block be" - API that doesn't promise too much. Call it something like "malloc_suggest_size(size_t minsize) ", and make the description something like ... "return the largest number of bytes that would not allocate a larger block of memory than the provided minsize, in the current memory situation", plus some veiled threats about not using this value to do anything fancy with pointers to already-allocated memory. -- Daniel Nebdal