comp.lang.ada
 help / color / mirror / Atom feed
From: Stephen Leake <Stephen.Leake@gsfc.nasa.gov>
Subject: user specified storage pools
Date: 1998/07/06
Date: 1998-07-06T00:00:00+00:00	[thread overview]
Message-ID: <uhg0u7vf4.fsf@gsfc.nasa.gov> (raw)


I've started playing with user specified storage pools, mainly to
implement a poor man's Purify to help test my list and binary tree
packages. It turned out to be simple to accomplish my main goal
(although I've found several compiler bugs in the process!).

However, I don't see how to cleanly provide users of the list package
the option of providing a user defined storage pool. Consider this
list package:

package Sal is

   -- Global access type, to allow specifying default storage pools for
   -- containers. Don't use for anything else!
   type Global_Access_Type is access all Integer;

end Sal;

with Ada.Finalization;
with System.Storage_Pools;
generic
   type Item_Type (<>) is limited private;
   type Item_Node_Type is private;
   with function To_Item_Node (Item : in Item_Type) return Item_Node_Type;
   with procedure Free_Item (Item : in out Item_Node_Type);
   -- <nice comments on how to instantiate this stuff>

   Node_Storage_Pool : in out System.Storage_Pools.Root_Storage_Pool'Class;
   -- Root_Storage_Pool is limited, which does not allow defaults.
   -- Default for a global list should be Sal.Global_Access_Type'Storage_Pool.
   -- Default for a local list, which should be reclaimed when the list
   -- type goes out of scope, is implementation defined (sigh).

package Sal.Lists_Single is

   ----------
   -- List operations

   < the usual stuff >

private
   type Node_Type;

   type Node_Access_Type is access Node_Type;
   for Node_Access_Type'Storage_Pool use Node_Storage_Pool;

   type Node_Type is record
      Item : Item_Node_Type;
      Next : Node_Access_Type;
   end record;

   type List_Type is new Ada.Finalization.Limited_Controlled with record
      Head : Node_Access_Type;
   end record;

end Sal.Lists_Single;

The question is how to make this easy for novices to instantiate,
while still providing power users the option of user specified storage
pools. Since Root_Storage_Pool is a limited type, we cannot specify a
default. Thus novices are forced to think about storage pools to use
this list package. On top of that, there is no way for the user to say
"just do what the compiler normally does"; that is, pretend the
'Storage_Pool clause for Node_Access_type was not present.

Is telling users to specify Sal.Global_Access_Type'Storage_Pool for
Node_Storage_Pool safe? For GNAT 3.10p it appears to be "what the
compiler normally does" for global types. However, I can envision a
more advanced compiler picking an allocation algorithm based on the
type (fixed size vs variable size, etc).

If Node_Storage_Pool was of type "access Root_Storage_Pool'class", it
could have a default. Then I could use a pre-processor to turn on or
off the 'Storage_Pool clause for Node_Access_Type. But I'd like a
better way!

-- Stephe




                 reply	other threads:[~1998-07-06  0:00 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed
replies disabled

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