home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!news.centerline.com!jimf
- From: jimf@centerline.com (Jim Frost)
- Newsgroups: comp.windows.x
- Subject: Re: FLAME, FLAME ON X!!!
- Date: 20 Nov 1992 19:32:56 GMT
- Organization: CenterLine Software, Inc.
- Lines: 47
- Message-ID: <1ejeh8INN1jq@armory.centerline.com>
- References: <RJC.92Nov13144522@daiches.cogsci.ed.ac.uk> <1992Nov16.162457.2923@osf.org> <1ebs7rINNp9k@armory.centerline.com> <1992Nov19.040434.12181@osf.org>
- NNTP-Posting-Host: 140.239.3.202
-
- dbrooks@osf.org (David Brooks) writes:
- >jimf@centerline.com (Jim Frost) writes:
-
- >>Unfortunately power-of-two allocation is remarkably wasteful of
- >>virtual memory (which means wasteful of real live swap space on many
- >>systems).
-
- >Then why have I heard people recommend using gnu malloc with X, people who
- >I thought would be in the know? The only gnu mallocs I've seen use
- >exclusively power-of-two allocation, and don't attempt to split a larger
- >block or merge blocks on free.
-
- Look at it this way -- if you do all allocations in a power of two
- then to have a list for every possible different sized allocation you
- need only thirty-two lists (actually 28 or 29 depending on the minimum
- allocation size, or even fewer if you consider that you can't really
- allocate a 4 gig area). That's real convenient -- you can basically
- find an empty space (if there is one) immediately, making your
- allocator REALLY fast. It's my assumption that that's what the GNU
- malloc does, although I've never looked it the code.
-
- The downside is that it's wasteful for allocations that don't fit
- well. An 65-byte allocation will return 128 bytes. No big deal, at
- least as long as you're not doing a lot of those allocations. As the
- sizes get larger, however, it becomes a really big deal -- a 1.1
- megabyte allocation will return 2 megabytes, for instance. Once you
- have a few of those you're starting to really waste memory.
-
- Most small programs -- and even a lot of large ones -- do few large
- allocations but a lot of small ones. For small allocations the
- lossage isn't too bad, so you get the performance win of finding free
- elements of the right size quickly without any real degredation.
-
- Things fall apart quickly for any application that actually needs to
- do many large allocations of odd sizes, though -- if the allocation
- doesn't fit well you start to loose megabytes. Thus for applications
- that do lots of large allocations it really pays to use something that
- fits allocations better. Further, it's really not that hard to make
- an algorithm that's just as fast as the power-of-two algorithm -- at
- least for a fair number of different small sizes. It's just harder
- than doing a power-of-two algorithm.
-
- Anyway this has gone off pretty far from X. If you want more
- discussion send me email.
-
- jim frost
- jimf@centerline.com
-