From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,427e29f23a651ddb X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!news.glorb.com!news.mv.net!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Finding out minimal allocation unit Date: Thu, 05 Apr 2007 09:07:48 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <20070403144350.6c95e085@cube.tz.axivion.com> <1175606570.4684.11.camel@localhost> <461257ea$1@news.post.ch> <4ecea2f308sbellon@sbellon.de> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls6.std.com 1175778468 3235 192.74.137.71 (5 Apr 2007 13:07:48 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Thu, 5 Apr 2007 13:07:48 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:+KzpcJJsUaGW9ZmqX4+NeZNASGc= Xref: g2news1.google.com comp.lang.ada:14793 Date: 2007-04-05T09:07:48-04:00 List-Id: Stefan Bellon writes: > Randy Brukardt wrote: >> Write your own storage pool that has the behavior you need. It's >> relatively easy to do, especially if you have fixed size elements. >> And then you can effectively use an array to allocate elements and >> still have cheap insertion and deletion and reordering. > > I'm a bit unclear about how to do it. Do I implement the Allocate using > the standard storage pool (i.e. using 'new') or do I interface it > directly to the underlying C library (i.e. using 'malloc')? In both > cases I still have the same problem as above. There are many ways to do it. In your case, you have a large number of small objects. In that case, it would make sense to allocate large chunks of memory (possibly using "new"), and then have Allocate chop them up into small pieces on request. If all objects are the same size, then Deallocate can put things on a single free list. If you have a small number of different small sizes, you can have one free list per size. The chunks might be of type Storage_Array, or might be an array-of-, depending on what's convenient. This is low level programming. If you mess up, you will have nasty bugs. > Are there examples of such a storage pool implementation around? I don't know. There should be. If I ever get enough spare time, I might create a library of useful pools, if such a thing doesn't already exist. - Bob