comp.lang.ada
 help / color / mirror / Atom feed
From: Bob Duff <bobduff@theworld.com>
Subject: Re: Dynamic allocation in the predefined language environment
Date: Tue, 07 Jul 2015 18:32:48 -0400
Date: 2015-07-07T18:32:48-04:00	[thread overview]
Message-ID: <87fv4zvbsf.fsf@theworld.com> (raw)
In-Reply-To: 559b9160$0$297$14726298@news.sunsite.dk

Matthias-Christian Ott <ott@mirix.org> writes:

> On 06/07/15 14:56, Bob Duff wrote:
>> 6   The execution of any construct raises Storage_Error if there is
>> insufficient storage for that execution. The amount of storage needed for the
>> execution of constructs is unspecified.
>
> I think that answers the first part of my question adequately, although
> its in a surprising part of the specification...

Well, it's hard to know where to put a rule that applies to pretty-much
every feature of the language.  I wouldn't want to duplicate it
in every section.  You were wondering about Unbounded_Strings, if
I recall correctly.  But I wouldn't want to say (in the section on
Unbounded_Strings) "operations in this package raise Storage_Error
if they run out of memory, and it's implementation dependent whether
they do", because there's nothing special about Unbounded_Strings
in that regard.

Perhaps Storage_Error should get its own section.  But with the language
as it is, it would be a pretty short section.  (I'd actually like to
add some functionality: a way to ensure that certain procedures
do NOT run out of memory.)

>... and the "any construct" is
> a bit ambiguous because it's in the dynamic semantics section of
> exception declarations but seems to refer to any construct in the language.

It says "execution of...", so it applies only to those constructs that
are executed (which includes "evaluated" and "elaborated").  Yes, that's
pretty-much "any construct".

And for sure it belongs under Dynamic Semantics, because it happens at
run time.

> If you follow the strong exception safety principle from C++, corrupted
> data structures should not be a problem.

I don't see how.  Storage_Error as defined by the language is like an
asynchronous interrupt.  When programming with asynchronous interrupts,
you need a way to disable interrupts in usually-short sections of code.
When programming with Storage_Error, you need a way to "disable" running
out of memory.  Ada lacks such a feature (and so does every other
programming language I know).

>...However, you can only do this
> in code that is under your control.
>
> You can somewhat avoid Storage_Error exception while handling
> Storage_Error exceptions by having "spare" memory that you free directly
> after the exception handler is invoked.

Yes, but Storage_Error is raised when running out of stack memory as
well as heap/pool memory.  Stack memory is the more "interesting" issue,
IMHO.  Imagine a "when Storage_Error" handler that simply prints a
message "Memory exhausted while processing line N of the input".
No heap-allocation involved, but in theory it can still raise
Storage_Error.

>...Otherwise there are many
> application-specific possibilities on how to deal with memory allocation
> errors in a spectrum ranging from simply aborting to degradation of
> service/user experience.

- Bob

  reply	other threads:[~2015-07-07 22:32 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-06 11:13 Dynamic allocation in the predefined language environment Matthias-Christian Ott
2015-07-06 13:04 ` G.B.
2015-07-06 14:21   ` Matthias-Christian Ott
2015-07-06 14:06 ` Bob Duff
2015-07-06 14:16   ` Matthias-Christian Ott
2015-07-06 14:23     ` G.B.
2015-07-06 14:43       ` Matthias-Christian Ott
2015-07-06 14:56         ` Bob Duff
2015-07-07  8:46           ` Matthias-Christian Ott
2015-07-07 22:32             ` Bob Duff [this message]
2015-07-08 19:47               ` Randy Brukardt
2015-07-08 21:08                 ` Bob Duff
2015-07-10 21:58                   ` Randy Brukardt
2015-07-08 21:16                 ` Dmitry A. Kazakov
2015-07-06 14:45     ` Bob Duff
2015-07-06 20:28       ` Randy Brukardt
2015-07-07  8:49       ` Matthias-Christian Ott
2015-07-07 22:14         ` Bob Duff
2015-07-06 15:29   ` Simon Wright
2015-07-06 20:31     ` Randy Brukardt
2015-07-06 21:35       ` Simon Wright
2015-07-07 18:29         ` Randy Brukardt
2015-07-06 20:22   ` Randy Brukardt
2015-07-06 18:45 ` Jeffrey R. Carter
2015-07-07  7:42 ` Dmitry A. Kazakov
2015-07-07  8:23   ` Matthias-Christian Ott
2015-07-07  8:46     ` Dmitry A. Kazakov
replies disabled

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