comp.lang.ada
 help / color / mirror / Atom feed
From: Graeme Perkes <graeme.perkes@sydney.gecm.com>
Subject: Creation of storage pools
Date: 1999/05/26
Date: 1999-05-26T00:30:50+00:00	[thread overview]
Message-ID: <374B411C.5EA8@sydney.gecm.com> (raw)

There is a snippet on Ada95 storage management at the Ada
source code treasury:

http://www.adapower.com/lang/mempool.html

I've found this example to be particularly useful for explaining
how to create pre-sized storage pools.

I'm trying to extend this concept by creating a package that allows
a set of named storage pools to be created. Applications will then
identify desired storage pools by name (i.e. a string).

This is my user-defined pool type: 

   type USER_POOL( SIZE : SYSTEM.STORAGE_ELEMENTS.STORAGE_COUNT;
                   NAME : POOL_NAME_PTR) is
      new SYSTEM.STORAGE_POOLS.ROOT_STORAGE_POOL with private;

   procedure ALLOCATE
      (
      POOL                     : in out USER_POOL;
      STORAGE_ADDRESS          :    out SYSTEM.ADDRESS;
      SIZE_IN_STORAGE_ELEMENTS : in
SYSTEM.STORAGE_ELEMENTS.STORAGE_COUNT;
      ALIGNMENT                : in
SYSTEM.STORAGE_ELEMENTS.STORAGE_COUNT
      );
     
   procedure DEALLOCATE
      (
      POOL                     : in out USER_POOL;
      STORAGE_ADDRESS          : in     SYSTEM.ADDRESS;
      SIZE_IN_STORAGE_ELEMENTS : in
SYSTEM.STORAGE_ELEMENTS.STORAGE_COUNT;
      ALIGNMENT                : in
SYSTEM.STORAGE_ELEMENTS.STORAGE_COUNT
      );      
     
   function STORAGE_SIZE
      (
      POOL : in USER_POOL
      )
      return SYSTEM.STORAGE_ELEMENTS.STORAGE_COUNT;
      
   function GET_POOL_NAME
      (
      POOL : in USER_POOL
      )
      return POOL_NAME;

I defined an access type for this type:

   type POOL_PTR is access all USER_POOL;

I defined an unconstrained array of POOL_PTRs:

   type POOL_LIST is array ( INTEGER range <> ) of POOL_PTR;

I defined a pointer to this type to allow it to be easily
passed to subprograms:

   type POOL_CFG_PTR is access all POOL_LIST;

Another package is initialised with a pools list:

   -- STORAGE_POOLS_LIST is populated by an initialisation procedure:

   MY_POOL : POOL_LIST.POOL_PTR := STORAGE_POOLS_LIST(I);

   type INT_ACC is access INTEGER;
   for INT_ACC'storage_pool use MY_POOL.all;

My test program is able to create a number of storage pools
and call operations such as GET_POOL_NAME, STORAGE_SIZE against
dereferenced elements of STORAGE_POOLS_LIST. These tests
have the desired affect.

The problem is how to use the storage pools I've created.
I'm having trouble with  "for XYZ'storage_pool use ..." syntax
when used with a USER_POOL access variable:

   STORAGE_POOLS_LIST : POOL_CFG_PTR := null;

   -- STORAGE_POOLS_LIST is populated by an initialisation procedure

   MY_POOL : POOL_LIST.POOL_PTR := STORAGE_POOLS_LIST(I);

   type INT_ACC is access INTEGER;
   for INT_ACC'storage_pool use MY_POOL.all;

GNAT 3.11b2 responds with the following error for the use clause:

	"incorrect reference to a Storage Pool"

What am I doing wrong?
What obscure syntax do I need?
Am I trying to violate basic principles of storage pools?

Cheers,
-- 
Graeme Perkes                        GEC Marconi Systems Pty Limited
mailto:graeme.perkes@gecms.com.au    40-52 Talavera Road, North Ryde
Tel: +61 2 9855 8961                 NSW 2113 Australia
Fax: +61 2 9855 8884




             reply	other threads:[~1999-05-26  0:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-05-26  0:00 Graeme Perkes [this message]
1999-06-04  0:00 ` Creation of storage pools Matthew Heaney
1999-06-04  0:00   ` Tucker Taft
1999-06-05  0:00 ` Simon Wright
1999-06-07  0:00   ` Graeme Perkes
1999-06-07  0:00     ` adam
replies disabled

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