comp.lang.ada
 help / color / mirror / Atom feed
* Creation of storage pools
@ 1999-05-26  0:00 Graeme Perkes
  1999-06-04  0:00 ` Matthew Heaney
  1999-06-05  0:00 ` Simon Wright
  0 siblings, 2 replies; 6+ messages in thread
From: Graeme Perkes @ 1999-05-26  0:00 UTC (permalink / 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




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Creation of storage pools
  1999-05-26  0:00 Creation of storage pools Graeme Perkes
@ 1999-06-04  0:00 ` Matthew Heaney
  1999-06-04  0:00   ` Tucker Taft
  1999-06-05  0:00 ` Simon Wright
  1 sibling, 1 reply; 6+ messages in thread
From: Matthew Heaney @ 1999-06-04  0:00 UTC (permalink / raw)


Graeme Perkes <graeme.perkes@sydney.gecm.com> writes:

> 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?

Aren't attribute rep clauses static?  You have to bind to a statically
declared storage pool object, not a dynamically declared one.

> What obscure syntax do I need?

  type My_Storage_Pool is new Root_Storage_Pool with ...;

  Storage_Pool : My_Storage_Pool;

  type Integer_Access is access Integer;

  for Integer_Access'Storage_Pool use Storage_Pool;


> Am I trying to violate basic principles of storage pools?

It would appear so.  

See the package System.Pool_Global, in the gnat sources, for an example.







^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Creation of storage pools
  1999-06-04  0:00 ` Matthew Heaney
@ 1999-06-04  0:00   ` Tucker Taft
  0 siblings, 0 replies; 6+ messages in thread
From: Tucker Taft @ 1999-06-04  0:00 UTC (permalink / raw)


Matthew Heaney wrote:
> 
> Graeme Perkes <graeme.perkes@sydney.gecm.com> writes:
> 
> > 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?
> 
> Aren't attribute rep clauses static?  

Not all of them.  Clearly those that require that the
expression denote a variable can't require that it be a static
expression.

> ... You have to bind to a statically
> declared storage pool object, not a dynamically declared one.

Not necessarily true in this case, though conceivably
GNAT may have such a restriction.  The only hard requirement 
is that the storage pool object denoted be a variable (see RM95 13.11(15)).

> ...
> > Am I trying to violate basic principles of storage pools?
> 
> It would appear so.

No, you are not violating any basic principle.  Conceivably
GNAT has a restriction (or bug) in this area.

> See the package System.Pool_Global, in the gnat sources, for an example.

-- 
-Tucker Taft   stt@averstar.com   http://www.averstar.com/~stt/
Technical Director, Distributed IT Solutions  (www.averstar.com/tools)
AverStar (formerly Intermetrics, Inc.)   Burlington, MA  USA




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Creation of storage pools
  1999-05-26  0:00 Creation of storage pools Graeme Perkes
  1999-06-04  0:00 ` Matthew Heaney
@ 1999-06-05  0:00 ` Simon Wright
  1999-06-07  0:00   ` Graeme Perkes
  1 sibling, 1 reply; 6+ messages in thread
From: Simon Wright @ 1999-06-05  0:00 UTC (permalink / raw)


Graeme Perkes <graeme.perkes@sydney.gecm.com> writes:

> 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);
               ^^^^^^^^^

(GNAT 3.11p)

When I compile an (edited) version with this error, I get

  use_pools.adb:5:47: incorrect reference to a Storage Pool
  pools.ads:37:14: invalid prefix in selected component "Pool_List"

Removing the error doesn't help.

Writing this works:

  with Pools;

  procedure Use_Pools is
    P : Pools.User_Pool renames Pools.My_Pool.all;
    type Int_Acc is access Integer;
    for Int_Acc'Storage_Pool use P;
  begin
    null;
  end Use_Pools;

Looks like time to submit a report (Graeme, I guess you _are_
supported? since you're using 3.11b2?)




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Creation of storage pools
  1999-06-07  0:00   ` Graeme Perkes
@ 1999-06-07  0:00     ` adam
  0 siblings, 0 replies; 6+ messages in thread
From: adam @ 1999-06-07  0:00 UTC (permalink / raw)


In article <375B1A89.53E3@sydney.gecm.com>,
  Graeme Perkes <graeme.perkes@sydney.gecm.com> wrote:

> Is "for X'Storage_Pool use MY_Pool.all" really a GNAT bug? The
> wording in RM95 13.11(15) indicates that a variable _name_ is
> required.

Nope, it doesn't say a variable name is required.  It says "the _name_
in a Storage_Pool clause shall denote a variable."  The terms don't mean
what you think they do.  "name" is defined in 4.1(2), and this
definition includes explicit dereferences (i.e. something.ALL).
"variable" is defined in 3.3(13) and basically refers to a view of an
object that can be changed.  3.3(9) says that the result of
dereferencing an "access-to-object" value (defined in 3.10(7)) is an
"object".  So if you string all this together, you find that
"MY_Pool.all" is indeed a name that denotes a variable.  (Unless I
missed something else, not at all unlikely.)

I suspect you were thinking that a "variable name" is the identifier
that you declared in a variable object declaration.  You have to be
careful when reading the RM not to assume terms mean what they look
like; often, the terms have formal definitions that don't quite match
how we're used to thinking about them.  I've stumbled across this a
number of times; in fact, keeping in mind how I embarrassed myself last
time I posted a question to c.l.a and didn't understand what one of the
terms meant, I had to look up "denote" in the index to make sure I was
understanding 13.11(15) correctly.

				-- Adam


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Creation of storage pools
  1999-06-05  0:00 ` Simon Wright
@ 1999-06-07  0:00   ` Graeme Perkes
  1999-06-07  0:00     ` adam
  0 siblings, 1 reply; 6+ messages in thread
From: Graeme Perkes @ 1999-06-07  0:00 UTC (permalink / raw)


Simon Wright wrote:
> 
> Writing this works:
> 
>   with Pools;
> 
>   procedure Use_Pools is
>     P : Pools.User_Pool renames Pools.My_Pool.all;
>     type Int_Acc is access Integer;
>     for Int_Acc'Storage_Pool use P;
>   begin
>     null;
>   end Use_Pools;
> 
> Looks like time to submit a report (Graeme, I guess you _are_
> supported? since you're using 3.11b2?)

Thanks for the advice. I was able to apply the above "hack"
successfully.

Is "for X'Storage_Pool use MY_Pool.all" really a GNAT bug? The
wording in RM95 13.11(15) indicates that a variable _name_ is
required.
                                                    
How do other compilers respond to the syntax I was trying to use?

Regards,
-- 
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




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~1999-06-07  0:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-05-26  0:00 Creation of storage pools Graeme Perkes
1999-06-04  0:00 ` 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

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