comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: A simple question about the "new" allocator
Date: Tue, 12 Aug 2014 09:35:11 +0200
Date: 2014-08-12T09:35:11+02:00	[thread overview]
Message-ID: <q8dnwsh5glsw.1f88qzc525z4r$.dlg@40tude.net> (raw)
In-Reply-To: d4137ad0-148a-4cf9-a6d8-c36e60ae7c9f@googlegroups.com

On Mon, 11 Aug 2014 23:54:50 -0700 (PDT), 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.

Write a custom memory pool that does not allocate anything. Make Test a
pointer to that pool.

P.S. It might sound silly, but such pools are actually useful. When the
object is already allocated and you want to initialize it and get a pointer
to, one way to do that is using a fake allocator.

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


  reply	other threads:[~2014-08-12  7:35 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 [this message]
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
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