comp.lang.ada
 help / color / mirror / Atom feed
From: porton@ex-code.com (Victor Porton)
Subject: Re: Pitfall: freeing access discriminants
Date: Fri, 14 Feb 2003 00:24:41 +0500
Date: 2003-02-13T19:32:47+00:00	[thread overview]
Message-ID: <E18jOyP-0005e2-00@porton.narod.ru> (raw)
In-Reply-To: uptpwoz8r.fsf@nasa.gov

In article <uptpwoz8r.fsf@nasa.gov>,
	Stephen Leake <Stephen.A.Leake@nasa.gov> writes:
> porton@ex-code.com (Victor Porton) writes:
> 
>> type Integer_Access is access Integer;
>> 
>> type T(D: access Integer) is Ada.Limited_Controlled with null record;
>> 
>> procedure Finalize(Object: in out T) is
>>   -- Error: cannot convert access discriminant to non-local access type
>>   D: Integer_Access := Integer_Access(Object.D);
>> begin
>>   Free(D);
>> end;
>> 
>> What to do? It seems being a serious deficiency in Ada or there are a 
>> workaround?
> 
> Why would you ever want to free an access discriminant? I usually use
> them to point to a constant object.
> 
> One good rule for dynamic memory allocation; never free something you
> did not allocate.

Just

X: T(new Integer'(12)); -- The real example is more natural
  -- than allocating an integer.

However I realized that Ada access discriminants are not to be used in 
such the way as this causes a great non-reliability. I switched to 
just record memebers of an access type.



  reply	other threads:[~2003-02-13 19:24 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-02-13 10:04 Pitfall: freeing access discriminants Victor Porton
2003-02-13 12:07 ` Victor Porton
2003-02-13 13:42   ` Preben Randhol
2003-02-13 17:40 ` Stephen Leake
2003-02-13 19:24   ` Victor Porton [this message]
  -- strict thread matches above, loose matches on Subject: below --
2003-02-13 12:41 Grein, Christoph
2003-02-13 13:38 ` Victor Porton
2003-02-13 20:49   ` tmoran
2003-02-13 21:17     ` Simon Wright
2003-02-14  4:16       ` tmoran
2003-02-14 21:30         ` Simon Wright
2003-02-14  8:28     ` Victor Porton
2003-02-22 19:00       ` Robert A Duff
2003-02-14  6:02 Grein, Christoph
2003-02-14  6:21 Grein, Christoph
replies disabled

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