comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: Using local storage pools...
Date: Thu, 24 Feb 2011 07:34:35 -0500
Date: 2011-02-24T07:34:35-05:00	[thread overview]
Message-ID: <wcclj15wqzo.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: j69bm6lufj730e02agm7dnnmd0l87ehbek@4ax.com

Brian Drummond <brian_drummond@btconnect.com> writes:

> I have been emailed privately, suggesting I report it to Adacore.

Sorry.  I emailed it by accident.  I meant to post it here.
Here it is:

Brian Drummond <brian_drummond@btconnect.com> writes:

> Arguably they cheat : they do not explicitly free each tree node (the "free"
> call has been deleted!) but free the entire pool at the end of the loop.
> But if that's valid, Ada should be able to do the same.

I don't think it's a "cheat".  This technique is commonly used.
I have used it in various compilers and static analysis tools
and other programs.  Whenever you have large numbers of small
heap-allocated objects that all have roughly the same lifetime,
this technique simplifies the program, makes it more efficient,
and helps avoid dangling pointers.

> http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gnat_ugn_unw/Some-Useful-Memory-Pools.html
> suggests System.Pool_Local offers a way to do likewise - a pool that is
> automatically reclaimed when it goes out of scope.

Pool_Local is not what you want (for efficiency) in this case.
What you want is a pool that allocates large chunks of memory,
and allocates individual small objects within that, and deallocates
the whole thing (all the chunks) at the end (Finalize).
For efficiency, you never call Unchecked_Deallocation.
I'm not sure if such a pool is part of gnatcoll, but if not,
I'll probably add it to gnatcoll someday.

Pool_Local would be more appropriate if the allocated objects are large
(and usually have similar lifetimes).

> This turns out to have its own performance problem, but that is another story...
>
> The question(or four)  for now is ... should the following really raise
> Storage_Error, i.e. am I doing something silly, and if so, what? 
> Or is this a bug in Gnat?

I don't see anything wrong with your code.  If you report it to AdaCore
(report@adacore.com) it will get fixed (at low priority, if you're not a
supported customer).  I'm interested in storage pools -- maybe I'll be
assigned to fix the bug (if it is a bug).

- Bob



  parent reply	other threads:[~2011-02-24 12:34 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-23 19:01 Using local storage pools Brian Drummond
2011-02-23 20:42 ` Dmitry A. Kazakov
2011-02-23 23:55   ` Brian Drummond
2011-02-24  9:26     ` Dmitry A. Kazakov
2011-02-24  9:51       ` Georg Bauhaus
2011-02-24 10:09         ` Dmitry A. Kazakov
2011-02-24 10:39         ` Brian Drummond
2011-02-23 20:51 ` Ludovic Brenta
2011-02-24  0:27   ` Brian Drummond
2011-02-24  8:03     ` Ludovic Brenta
2011-02-24 17:04       ` Brian Drummond
2011-02-24 12:34     ` Robert A Duff [this message]
2011-02-23 21:01 ` Simon Wright
2011-02-24  0:00   ` Brian Drummond
2011-02-26  3:02 ` Randy Brukardt
2011-02-26 18:41   ` Pascal Obry
2011-02-26 18:59     ` Pascal Obry
2011-02-26  3:07 ` Randy Brukardt
2011-02-26  8:41 ` anon
2011-02-26 10:42   ` Pascal Obry
2011-02-26 11:41   ` Ludovic Brenta
2011-02-27  4:16     ` anon
2011-02-27  8:18       ` Pascal Obry
2011-02-27 23:46         ` Georg Bauhaus
replies disabled

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