comp.lang.ada
 help / color / mirror / Atom feed
From: sbelmont700@gmail.com
Subject: Re: A simple question about the "new" allocator
Date: Tue, 12 Aug 2014 03:29:01 -0700 (PDT)
Date: 2014-08-12T03:29:01-07:00	[thread overview]
Message-ID: <a93a7da9-e3cc-410f-a7dc-f81ea8c179e5@googlegroups.com> (raw)
In-Reply-To: <d4137ad0-148a-4cf9-a6d8-c36e60ae7c9f@googlegroups.com>

On Tuesday, August 12, 2014 2:54:50 AM UTC-4, NiGHTS wrote:
> With all default configurations using a typical Ada compiler, will the following code run indefinitely without fail or will it eventually crash?
> 

Note that you are (intentionally or otherwise) using an 'anonymous allocator' for which the rules are much different, however as written it would still eventually crash.  Apart from the simple advice of just not using an allocator to begin with, I would expect the following to not leak any memory:

procedure main is
begin 
  loop 
    declare
      Test : access Positive := new Positive;
    begin
      null;
    end;
  end loop; 
end main; 

But it seems hit or miss whether or not a given compiler does this in the advised manner (mine doesn't seem to).  On the other hand, this seems to work more consistently:

procedure main is
  type T (x : access Positive) is null record;
begin 
   loop 
     declare
       Test : T (x => new Positive);
     begin
       null;
     end;
    end loop; 
end main;

Of course, there is still no real advantage to any of this over just a regular object.

-sb

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