Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Question: What's the difference between pools of pools and Ada 2012's new subpools?

100 views
Skip to first unread message

Shark8

unread,
Feb 13, 2013, 7:12:06 PM2/13/13
to
I recently asked this question on Stackoverflow ( http://stackoverflow.com/questions/14840702/what-are-the-differerences-between-the-new-ada-sub-pool-features-and-pools-of-po ).

I haven't used pools at all, yet; so it's quite likely I'm missing something.

-------
-- Pool of Pools
----------------------------------
-- Minnesota: Land of 10,000 Lakes
type Minnesota(Size: Storage_Count) is new Root_Storage_Pool with private;
type Lake(Size: Storage_Count) is new Root_Storage_Pool with private
with Storage_Pool => Minnasota;
-- ...
type Pooled is [...] with Storage_Pool => Lake;

-------
-- Sub-Pools
----------------------------------
type Pond(Size: Storage_Count) is new Root_Storage_Pool_With_Subpools with private;
subtype My_Handle is Subpool_Handle;

[Note: examples uncompiled, just for illustrative purpose]

Randy Brukardt

unread,
Feb 13, 2013, 7:56:42 PM2/13/13
to
"Shark8" <onewing...@gmail.com> wrote in message
news:8fe47d10-1889-43e7...@googlegroups.com...
>I recently asked this question on Stackoverflow (
>http://stackoverflow.com/questions/14840702/what-are-the-differerences-between-the-new-ada-sub-pool-features-and-pools-of-po )
>.
>
> I haven't used pools at all, yet; so it's quite likely I'm missing
> something.
>
> -------
> -- Pool of Pools
> ----------------------------------
> -- Minnesota: Land of 10,000 Lakes
> type Minnesota(Size: Storage_Count) is new Root_Storage_Pool with private;
> type Lake(Size: Storage_Count) is new Root_Storage_Pool with private
> with Storage_Pool => Minnasota;

Aspect Storage_Pool only applies to access types (13.11(15) and others), and
type Lake is not an access type, so this is illegal (and makes no sense as
well).

You could implement one pool by putting other pools within its
implementation (say Minnesota here including a an array of 10000 Lakes :-).
But you'd then have to have a way to select which item belongs to each,
ahem, subpool. And you'd be reinventing the wheel.

There is also the issue of finalization. The subpool mechanism ensures that
objects don't outlive their subpool (pointers to the objects might outlive
the subpool, but not the object themselves), even when the subpool is
explicitly destroyed early (just as Unchecked_Deallocation does). There's no
good way to do that without language support (every hand-written subpool
implementation that we talked about insisted that no controlled, protected,
or task objects be allocated from it, which is obviously limiting).

Let me assure you, getting this right was hard and contentious. It was
nearly dropped a couple of times. Doing it yourself wouldn't be contentious
(I hope!), but it would still be hard. Since the ARG has already done the
dirty work, it's best to use it.

Randy.


Randy.


Randy.


Shark8

unread,
Feb 13, 2013, 9:34:16 PM2/13/13
to
Thank you for that explanation, it's quite informative.

Shark8

unread,
Feb 16, 2013, 8:06:02 PM2/16/13
to
Secondary questions:

Are there any good tutorials-on/examples-of using pools?
Subpools?

Dmitry A. Kazakov

unread,
Feb 17, 2013, 4:06:44 AM2/17/13
to
On Sat, 16 Feb 2013 17:06:02 -0800 (PST), Shark8 wrote:

> Are there any good tutorials-on/examples-of using pools?

Stack pools ("arenas"):

http://www.dmitry-kazakov.de/ada/components.htm#Pools_etc

Using pools for injecting data into objects ("multiple inheritance"), e.g.
list headers, graph node headers:

http://www.dmitry-kazakov.de/ada/components.htm#Generic_Doubly_Linked_Web
http://www.dmitry-kazakov.de/ada/components.htm#Generic_Directed_Graph

> Subpools?

Not yet. Subpools could be useful for concurrent and heavy duty
applications.

As Randy said the problem with pools when used for management the life
cycle of objects is finalization of controlled objects. If subpools
alleviate this problem is to be seen.

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

Simon Wright

unread,
Feb 17, 2013, 6:47:11 AM2/17/13
to
"Dmitry A. Kazakov" <mai...@dmitry-kazakov.de> writes:

> As Randy said the problem with pools when used for management the life
> cycle of objects is finalization of controlled objects. If subpools
> alleviate this problem is to be seen.

What Randy said was that the _hand-written_ subpool implementations the
ARG had seen had problems with finalizable objects. Of coaurse, in the
end all implementations are hand-written by somebody.

Randy Brukardt

unread,
Feb 18, 2013, 6:24:34 PM2/18/13
to
"Simon Wright" <si...@pushface.org> wrote in message
news:lyd2vzq...@pushface.org...
Right (I think). When you create your own subpool-like mechanism, you can't
force finalization of objects (unless you keep a list of objects in the
subpool and free them individually, which would defeat the purpose). So most
people's simply say that they cannot be used with controlled objects (or
tasks or protected objects). Which is limiting.

The subpool mechanism in Ada 2012 is designed to ensure that objects are
finalized no later than when the subpool is discarded (via
Unchecked_Deallocate_Subpool). In that sense, it works just like
Unchecked_Deallocation (except all at once, rather than one at a time). Of
course, I can't know whether GNAT actually implements this correctly!

Randy.


0 new messages