comp.lang.ada
 help / color / mirror / Atom feed
From: anon@anon.org (anon)
Subject: Re: Allocators and exceptions => Trying Again
Date: Mon, 10 Sep 2007 22:10:29 GMT
Date: 2007-09-10T22:10:29+00:00	[thread overview]
Message-ID: <phjFi.522519$p47.409017@bgtnsc04-news.ops.worldnet.att.net> (raw)
In-Reply-To: 1189426567.755739.178270@r29g2000hsg.googlegroups.com

The Constraint_Error will not alter the memory allocation. The only 
exception that effect memory allocation is the system generated 
Storage_Error. No other exception will alter memory. Which 
denotes a memory leak.

Programmers can confuse the compiler that creates and allows memory 
leaked or unexplained deallocates.  And its not the languages fault but 
the programmers. This might explain why it is not defined directly in 
the RM.


The problem is that even though it is legal to have 

  type T (Init : Integer) is record
     C : Positive := Positive (Init);
  end record;
 
It does allows the concept of memory leaks to be introduce into a 
program. Some compile may use deallocation others may allow memory 
leaked, while other might do type checking first and generate the 
Constraint_Error before memory is allocate.

If you used, instead:

  type T (Init : Positive ) is record
     C : Positive := Init ;
  end record ;

then do the integer to positive conversion in the body like

-- Note:  Ptr := new T ( Positive ( -5 ) ); will generate a 
-- compiler warning, so

  C_Value : Constant Integer := -5 ;

  Ptr := new T ( Positive ( C_Value ) ) ;


In this design the conversion of the Integer to Positive will generate 
the exception, before the system trys to allocate any memory. Which 
Guarantees, when the exception will happen and the programmer can 
predict how the system will react, else there is no Guarantee.


For Memory Leaks: 

Read Chapter 21, of the "GNAT User Guide" it deals with 
memory leaks, with the use of debugging and "gnatmem". The 
example they use may not be like yours but in reading it 
you should be able to adapt the concept to your code.


In <1189426567.755739.178270@r29g2000hsg.googlegroups.com>,  Maciej Sobczak <see.my.homepage@gmail.com> writes:
>On 10 Wrz, 12:37, a...@anon.org (anon) wrote:
>
>>         pragma Restrictions ( Immediate_Reclamation ) ;
>
>It does not apply to objects created by the allocator.
>
>It is useful only for those objects that are created implicitly, for
>example return values of unconstrained types.
>
>My question still holds. And I'm still scared.
>
>--
>Maciej Sobczak
>http://www.msobczak.com/
>




  reply	other threads:[~2007-09-10 22:10 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-09  7:40 Allocators and exceptions Maciej Sobczak
2007-09-09 12:17 ` anon
2007-09-09 20:31   ` Maciej Sobczak
2007-09-09 22:43     ` Simon Wright
2007-09-10 12:10       ` Maciej Sobczak
2007-09-10 19:08         ` Simon Wright
2007-09-10  2:56     ` anon
2007-09-10 12:42     ` Dmitry A. Kazakov
2007-09-10 21:48       ` Maciej Sobczak
2007-09-11  9:16         ` Dmitry A. Kazakov
2007-09-11  9:19           ` Maciej Sobczak
2007-09-11 12:27             ` Dmitry A. Kazakov
2007-09-11 19:07               ` Maciej Sobczak
2007-09-11 22:56                 ` Georg Bauhaus
2007-09-12 12:36                   ` Maciej Sobczak
2007-09-12 22:19                     ` Randy Brukardt
2007-09-12  9:32                 ` Dmitry A. Kazakov
2007-09-12 12:42                   ` Maciej Sobczak
2007-09-12 15:25                     ` Dmitry A. Kazakov
2007-09-12 12:29             ` Stephen Leake
2007-09-12 12:46               ` Maciej Sobczak
2007-09-12 20:53                 ` Simon Wright
2007-09-12 22:32                   ` Randy Brukardt
2007-09-12 23:43                     ` Simon Wright
2007-09-13  3:42                       ` Randy Brukardt
2007-09-13  3:36                     ` Randy Brukardt
2007-09-13  9:43                     ` Maciej Sobczak
2007-09-12 22:25                 ` Randy Brukardt
2007-09-13 11:51                 ` Stephen Leake
2007-09-12 14:14               ` Markus E L
2007-09-10 10:37 ` Allocators and exceptions => Read Me First anon
2007-09-10 12:16   ` Maciej Sobczak
2007-09-10 22:10     ` anon [this message]
2007-09-10 23:15       ` Allocators and exceptions => Trying Again Markus E L
2007-09-10 15:44 ` Allocators and exceptions Adam Beneschan
2007-09-10 21:58   ` Maciej Sobczak
2007-09-10 22:07   ` Jeffrey R. Carter
2007-09-11  9:14   ` Dmitry A. Kazakov
2007-09-11  9:23     ` Maciej Sobczak
2007-09-11  2:36 ` Randy Brukardt
2007-09-11 15:33   ` Adam Beneschan
2007-09-11 19:21     ` Maciej Sobczak
2007-09-11 21:56     ` Adam Beneschan
2007-09-12  0:34       ` Jeffrey R. Carter
2007-09-12 12:13         ` Maciej Sobczak
2007-09-12 16:34           ` Jeffrey R. Carter
2007-09-12 23:50             ` Jeffrey R. Carter
2007-09-12 12:22       ` Maciej Sobczak
2007-09-12 14:11         ` Markus E L
2007-09-12 16:08         ` Adam Beneschan
2007-09-12 20:35           ` Dmitry A. Kazakov
2007-09-12 21:01             ` Adam Beneschan
2007-09-12 22:45             ` Randy Brukardt
2007-09-13  7:48               ` Dmitry A. Kazakov
2007-09-12  3:08 ` Allocators and exceptions -- Debugging says memory leak! anon
replies disabled

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