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!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!inka.de!rz.uni-karlsruhe.de!news.uni-stuttgart.de!not-for-mail From: Stefan Bellon Newsgroups: comp.lang.ada Subject: Re: Finding out minimal allocation unit Date: Tue, 3 Apr 2007 15:28:09 +0200 Organization: Comp.Center (RUS), U of Stuttgart, FRG Message-ID: <20070403152809.2cddf217@cube.tz.axivion.com> References: <20070403144350.6c95e085@cube.tz.axivion.com> <1175606570.4684.11.camel@localhost> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Trace: infosun2.rus.uni-stuttgart.de 1175606852 12987 129.69.226.23 (3 Apr 2007 13:27:32 GMT) X-Complaints-To: news@news.uni-stuttgart.de NNTP-Posting-Date: Tue, 3 Apr 2007 13:27:32 +0000 (UTC) X-Newsreader: Sylpheed-Claws 2.6.0 (GTK+ 2.8.20; i486-pc-linux-gnu) X-URL: http://www.axillion.de/ Xref: g2news1.google.com comp.lang.ada:14762 Date: 2007-04-03T15:28:09+02:00 List-Id: Georg Bauhaus wrote: > On Tue, 2007-04-03 at 14:43 +0200, Stefan Bellon wrote: > > > Is there a reliable way of finding out the smallest allocation unit? > > type LP is -- new ... with > record > forward: access LP; > backward: access LP; > end record; > for LP'Size use 63; > > should make the compiler complain when 63 bits aren't enough. Ok, but when wanting to calculate it in a generic, it gets lots harder. At present we are using something like this: generic type Item_Type is private; with function Equal (X, Y : in Item_Type) return Boolean is "="; Min_Elements_In_Cell : in Positive := 1; -- The minimum amount of Item_Type elements that should be in -- one array cell of the B-List. Min_Allocation_Size : in Positive := 32 * 8; -- 32 Bytes -- Minimum size of a list cell. List cells are allocated in powers of -- two and so that at least Min_Elements_In_Cell of type Item_Type -- fit into one cell. package BLists is -- ... private type Cell; type List is access Cell; function Power2_Ceiling (N : in Natural) return Natural; -- Calculates the next larger power-of-two with regard to N. Misc_Data_In_Bits : constant Natural := Natural'Size + List'Size; -- Size of Item_Type-independent data in the cell record. type Dummy_Array is array (Natural range 1 .. 1) of Item_Type; Item_Size : constant Natural := Dummy_Array'Component_Size; -- Use the dummy array in order to find out the size the Item_Type -- takes in an array in order to calculate the correct size below. Cell_Size_In_Bits : constant Natural := Natural'Max (Min_Allocation_Size, Power2_Ceiling (Misc_Data_In_Bits + Min_Elements_In_Cell * Item_Size)); -- Calculated cell size to best fit an allocation unit. Array_Size : constant Natural := (Cell_Size_In_Bits - Misc_Data_In_Bits) / Item_Size; -- Amount of Item_Types fitting into one cell. type Item_Array is array (Natural range 1 .. Array_Size) of Item_Type; type Cell is record First_Used : Natural; Next : List; Elements : Item_Array; end record; -- Fill the array from 'Last down to 'First and First_Used denotes -- the first used entry, this results in faster prepending. end BLists; But this way your suggestion does not work anymore as the 'Size attribute must be static. -- Stefan Bellon