From: Adam Beneschan <adambeneschan@gmail.com>
Subject: Re: A simple question about the "new" allocator
Date: Tue, 12 Aug 2014 08:10:40 -0700 (PDT)
Date: 2014-08-12T08:10:40-07:00 [thread overview]
Message-ID: <b553feff-e281-43d7-8313-e204ed827a06@googlegroups.com> (raw)
In-Reply-To: <d4137ad0-148a-4cf9-a6d8-c36e60ae7c9f@googlegroups.com>
On Monday, August 11, 2014 11:54:50 PM UTC-7, NiGHTS wrote:
> With all default configurations using a typical Ada compiler, will the following code run indefinitely without fail or will it eventually crash?
>
>
>
> procedure main is
> Test : access Positive;
> begin
> loop
> Test := new Positive;
> end loop;
> end main;
> If this does crash, what would be another way to write this program so that it does not crash? I would prefer not to use Ada.Unchecked_Deallocation.
I vote for
procedure main is
begin
loop
null;
end loop;
end main;
which would have the same effect as your orignal code but without crashing. Really, the question "what would be another way to write this program so that it does not crash" makes no sense at all; before answering it, we would need specifics about just *what* you want to do without crashing.
For example, if you want "test := new Positive" to automatically deallocate the previously allocated Positive, since it isn't referenced any more, there are various "smart pointer" packages out there that keep a reference count.
But the question as posted isn't answerable.
-- Adam
next prev parent reply other threads:[~2014-08-12 15:10 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-12 6:54 A simple question about the "new" allocator NiGHTS
2014-08-12 7:35 ` Dmitry A. Kazakov
2014-08-12 13:38 ` G.B.
2014-08-12 10:29 ` sbelmont700
2014-08-12 18:49 ` Shark8
2014-08-12 19:10 ` Adam Beneschan
2014-08-12 21:53 ` Niklas Holsti
2014-08-12 22:34 ` Adam Beneschan
2014-08-12 23:14 ` sbelmont700
2014-08-12 23:41 ` Adam Beneschan
2014-08-13 7:36 ` Dmitry A. Kazakov
2014-08-13 15:04 ` Adam Beneschan
2014-08-13 20:32 ` Niklas Holsti
2014-08-12 15:10 ` Adam Beneschan [this message]
2014-08-12 16:07 ` Jeffrey Carter
2014-08-12 19:58 ` Robert A Duff
2014-08-12 17:51 ` NiGHTS
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox