comp.lang.ada
 help / color / mirror / Atom feed
* Emulating placement new
@ 2012-07-29 13:56 Florian Weimer
  2012-07-29 14:10 ` Dmitry A. Kazakov
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Florian Weimer @ 2012-07-29 13:56 UTC (permalink / raw)


Is there a way to specify a storage pool (or something similar) on the
allocator, and not on the access type?



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

* Re: Emulating placement new
  2012-07-29 13:56 Emulating placement new Florian Weimer
@ 2012-07-29 14:10 ` Dmitry A. Kazakov
  2012-07-29 14:15   ` Florian Weimer
  2012-07-29 15:00 ` Georg Bauhaus
  2012-07-29 16:04 ` Robert A Duff
  2 siblings, 1 reply; 8+ messages in thread
From: Dmitry A. Kazakov @ 2012-07-29 14:10 UTC (permalink / raw)


On Sun, 29 Jul 2012 15:56:27 +0200, Florian Weimer wrote:

> Is there a way to specify a storage pool (or something similar) on the
> allocator, and not on the access type?

Qualified expression?

   Access_Type'(new T)

Maybe something like this:

   function Allocate_In (Pool : in out Root_Storage_Pool'Class)
       return not null access T is
       type T_Ptr is access T;
       for T_Ptr'Storage_Pool use Pool;
       Ptr : T_Ptr;
   begin
       Ptr := new T;
       return Ptr.all'Unchecked_Access;
   end Allocate_In;

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



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

* Re: Emulating placement new
  2012-07-29 14:10 ` Dmitry A. Kazakov
@ 2012-07-29 14:15   ` Florian Weimer
  2012-07-29 14:25     ` Dmitry A. Kazakov
  0 siblings, 1 reply; 8+ messages in thread
From: Florian Weimer @ 2012-07-29 14:15 UTC (permalink / raw)


* Dmitry A. Kazakov:

> On Sun, 29 Jul 2012 15:56:27 +0200, Florian Weimer wrote:
>
>> Is there a way to specify a storage pool (or something similar) on the
>> allocator, and not on the access type?

> Maybe something like this:
>
>    function Allocate_In (Pool : in out Root_Storage_Pool'Class)
>        return not null access T is
>        type T_Ptr is access T;
>        for T_Ptr'Storage_Pool use Pool;
>        Ptr : T_Ptr;
>    begin
>        Ptr := new T;
>        return Ptr.all'Unchecked_Access;
>    end Allocate_In;

This doesn't work for unconstrained types.



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

* Re: Emulating placement new
  2012-07-29 14:15   ` Florian Weimer
@ 2012-07-29 14:25     ` Dmitry A. Kazakov
  0 siblings, 0 replies; 8+ messages in thread
From: Dmitry A. Kazakov @ 2012-07-29 14:25 UTC (permalink / raw)


On Sun, 29 Jul 2012 16:15:01 +0200, Florian Weimer wrote:

> * Dmitry A. Kazakov:
> 
>> On Sun, 29 Jul 2012 15:56:27 +0200, Florian Weimer wrote:
>>
>>> Is there a way to specify a storage pool (or something similar) on the
>>> allocator, and not on the access type?
> 
>> Maybe something like this:
>>
>>    function Allocate_In (Pool : in out Root_Storage_Pool'Class)
>>        return not null access T is
>>        type T_Ptr is access T;
>>        for T_Ptr'Storage_Pool use Pool;
>>        Ptr : T_Ptr;
>>    begin
>>        Ptr := new T;
>>        return Ptr.all'Unchecked_Access;
>>    end Allocate_In;
> 
> This doesn't work for unconstrained types.

Why?

   Ptr := new T (discriminants);

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



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

* Re: Emulating placement new
  2012-07-29 13:56 Emulating placement new Florian Weimer
  2012-07-29 14:10 ` Dmitry A. Kazakov
@ 2012-07-29 15:00 ` Georg Bauhaus
  2012-07-29 16:04 ` Robert A Duff
  2 siblings, 0 replies; 8+ messages in thread
From: Georg Bauhaus @ 2012-07-29 15:00 UTC (permalink / raw)


On 29.07.12 15:56, Florian Weimer wrote:
> Is there a way to specify a storage pool (or something similar) on the
> allocator, and not on the access type?
>

Would subpools do? (I see that the access type's storage pool must be a
Root_Storage_Pool_With_Subpools.)

allocator ::=
    new [subpool_specification] subtype_indication
  | new [subpool_specification] qualified_expression

subpool_specification ::= (subpool_handle_name)




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

* Re: Emulating placement new
  2012-07-29 13:56 Emulating placement new Florian Weimer
  2012-07-29 14:10 ` Dmitry A. Kazakov
  2012-07-29 15:00 ` Georg Bauhaus
@ 2012-07-29 16:04 ` Robert A Duff
  2012-07-29 18:48   ` Florian Weimer
  2 siblings, 1 reply; 8+ messages in thread
From: Robert A Duff @ 2012-07-29 16:04 UTC (permalink / raw)


Florian Weimer <fw@deneb.enyo.de> writes:

> Is there a way to specify a storage pool (or something similar) on the
> allocator, and not on the access type?

Ada 2012 has such a feature.  Instead of:

    X := new T'(This => 123, That => 456);

which allocates in T's storage pool, you can say:

    X := new (My_Pool) T'(This => 123, That => 456);

which allocates in My_Pool.

Look up "subpools" in the Ada 2012 RM for details.

For "placement new", you will want to write a pool
that takes an address-to-allocate-at as a discriminant.

- Bob



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

* Re: Emulating placement new
  2012-07-29 16:04 ` Robert A Duff
@ 2012-07-29 18:48   ` Florian Weimer
  2012-07-29 19:14     ` Robert A Duff
  0 siblings, 1 reply; 8+ messages in thread
From: Florian Weimer @ 2012-07-29 18:48 UTC (permalink / raw)


* Robert A. Duff:

> Florian Weimer <fw@deneb.enyo.de> writes:
>
>> Is there a way to specify a storage pool (or something similar) on the
>> allocator, and not on the access type?
>
> Ada 2012 has such a feature.  Instead of:
>
>     X := new T'(This => 123, That => 456);
>
> which allocates in T's storage pool, you can say:
>
>     X := new (My_Pool) T'(This => 123, That => 456);
>
> which allocates in My_Pool.

Interesting.  But think this goes into the wrong direction.  The owner
pool still controls the allocation, Allocate_From_Subpool dispatches
on the master pool, not the subpool.  So I'd still need a special
access type type inject the owner pool.



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

* Re: Emulating placement new
  2012-07-29 18:48   ` Florian Weimer
@ 2012-07-29 19:14     ` Robert A Duff
  0 siblings, 0 replies; 8+ messages in thread
From: Robert A Duff @ 2012-07-29 19:14 UTC (permalink / raw)


Florian Weimer <fw@deneb.enyo.de> writes:

> Interesting.  But think this goes into the wrong direction.  The owner
> pool still controls the allocation, Allocate_From_Subpool dispatches
> on the master pool, not the subpool.

I don't see the problem.  The allocator specifies the subpool, and
Allocate_From_Subpool takes the subpool as a parameter.  It could
dispatch on some operation of the subpool, if you want, but for
placement new, you don't even need that -- you just need the
address to allocate at.

>...So I'd still need a special
> access type type inject the owner pool.

I'm not sure what you mean.  You have to attach the "master pool"
to each access type that you want to work this way.  Is that
what you mean?

You don't need a new access type for each allocation address.
That wouldn't work anyway due to accessibility rules, which
is the weakness that subpools are trying to address.

You might also be interested in pragma Default_Storage_Pool,
which can be used to specify the pool for all access types in a
given subsystem, or (with "null") can be used to make sure
you don't forget to specify pools explicitly.

- Bob



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

end of thread, other threads:[~2012-08-06 17:10 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-29 13:56 Emulating placement new Florian Weimer
2012-07-29 14:10 ` Dmitry A. Kazakov
2012-07-29 14:15   ` Florian Weimer
2012-07-29 14:25     ` Dmitry A. Kazakov
2012-07-29 15:00 ` Georg Bauhaus
2012-07-29 16:04 ` Robert A Duff
2012-07-29 18:48   ` Florian Weimer
2012-07-29 19:14     ` Robert A Duff

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