comp.lang.ada
 help / color / mirror / Atom feed
From: Stefan Bellon <sbellon@sbellon.de>
Subject: Re: Finding out minimal allocation unit
Date: Tue, 3 Apr 2007 15:28:09 +0200
Date: 2007-04-03T15:28:09+02:00	[thread overview]
Message-ID: <20070403152809.2cddf217@cube.tz.axivion.com> (raw)
In-Reply-To: 1175606570.4684.11.camel@localhost

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



  reply	other threads:[~2007-04-03 13:28 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-04-03 12:43 Finding out minimal allocation unit Stefan Bellon
2007-04-03 13:22 ` Georg Bauhaus
2007-04-03 13:28   ` Stefan Bellon [this message]
2007-04-03 13:34   ` Martin Krischik
2007-04-03 13:37     ` Stefan Bellon
2007-04-03 15:17       ` Markus E Leypold
2007-04-04 17:16         ` Robert A Duff
2007-04-05  8:55           ` Markus E Leypold
2007-04-05 17:55             ` Stefan Bellon
2007-04-06  1:40               ` Randy Brukardt
2007-04-06  8:06                 ` Stefan Bellon
2007-04-06 11:06                   ` Markus E Leypold
2007-04-03 23:53     ` Randy Brukardt
2007-04-05  6:12       ` Stefan Bellon
2007-04-05  7:35         ` Martin Krischik
2007-04-05 17:58           ` Stefan Bellon
2007-04-07  9:27             ` Martin Krischik
2007-04-10 21:42             ` Robert A Duff
2007-04-05 13:07         ` Robert A Duff
2007-04-05 18:02           ` Stefan Bellon
2007-04-06  1:31             ` Randy Brukardt
2007-04-06  8:10               ` Stefan Bellon
2007-04-06 17:17                 ` Simon Wright
2007-04-06 12:38         ` Stephen Leake
2007-04-03 14:12   ` Larry Kilgallen
2007-04-03 13:48 ` Robert A Duff
2007-04-03 16:45 ` Dmitry A. Kazakov
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox