*BSD News Article 34179


Return to BSD News archive

Xref: sserve comp.os.386bsd.questions:12272 comp.os.386bsd.development:2375 comp.os.386bsd.misc:3152
Newsgroups: comp.os.386bsd.questions,comp.os.386bsd.development,comp.os.386bsd.misc
Path: sserve!newshost.anu.edu.au!harbinger.cc.monash.edu.au!msuinfo!agate!howland.reston.ans.net!math.ohio-state.edu!magnus.acs.ohio-state.edu!csn!boulder.parcplace.com!imp
From: imp@boulder.parcplace.com (Warner Losh)
Subject: Re: Why does FreeBSD 1.1.5 say gets() is unsafe?
Message-ID: <CuE00K.8LI@boulder.parcplace.com>
Sender: news@boulder.parcplace.com
Organization: ParcPlace Boulder
References: <311m2e$o33@agate.berkeley.edu> <324v1b$14g@boavista.bln.sub.org> <1994Aug10.151130.1017@rhodes>
Date: Thu, 11 Aug 1994 20:09:55 GMT
Lines: 30

In article <1994Aug10.151130.1017@rhodes> stuart@zen.mathcs.rhodes.edu
(Brian L. Stuart) writes: 
>At the risk of picking an excessively fine nit (and mixing my metaphors),
>a good argument can be made for doubling the size of the array rather
>than adding a fixed amount.
[ summary about why this is good ]

I'd like to add that many libraries can make good use of 1.5x the
space rather than 2x the space.  Any geometric progression (almost)
yields good results, with 2x being the easiest to implement.  I've
seen numbers ranging from 1.1 to 8 used on realloc schemes and the
best ones seem to have a numebr > 1.5 but < 2.5 for most buffers with
a largish (4k-8k) start size.  The smaller the start size, the larger
the "doubling" factor you want to use, in general.  Keep in mind that
if you start with 1k and double that you will only save 1 realloc over
starting with 2k and doubling.

I think there is something in knuth about tuning, but I can't seem to
find it now.

OTOH, if you know that the allocation will always be about x bytes and
that if will vary within an order of magnitude, the space savings may
be worth the worst case behaviour.  For readline, most of the time
you'll be reading in lines <= 1k.

Warner
-- 
Warner Losh		imp@boulder.parcplace.COM	ParcPlace Boulder
"... but I can't promote you to "Prima Donna" unless you demonstrate a few
 more serious personality disorders"