From: anon@anon.org (anon)
Subject: Re: Allocators and exceptions
Date: Mon, 10 Sep 2007 02:56:36 GMT
Date: 2007-09-10T02:56:36+00:00 [thread overview]
Message-ID: <En2Fi.82051$ax1.45449@bgtnsc05-news.ops.worldnet.att.net> (raw)
In-Reply-To: 1189369871.672082.162750@50g2000hsm.googlegroups.com
May be this will answer you question in a little more deal.
This is mainly an operating system or an operating environment routines
question that deal with the "HEAP" and not for the RM. From the links
in System.Memory:
function c_malloc (Size : size_t) return System.Address;
pragma Import (C, c_malloc, "malloc");
and
function c_realloc
(Ptr : System.Address; Size : size_t) return System.Address;
pragma Import (C, c_realloc, "realloc");
either the "malloc" or "realloc" will normally return a pointer to the
memory if and only if the complete block being allocation is available in
the heap. But if less than requested size is available then the routines
just returns a "NULL" denoting a error condition, and the Ada routine
raises an Storage_Error with information about the heap being exhausted.
Also the remaining unattracted heap memory is still there.
An Example:
with Ada.Text_IO ;
--
-- If the Heap is set to 128 bytes.
--
procedure test is
type szp is access string ;
name : szp ;
begin
Ada.Text_IO.Put_Line ( "Heap Size = 128" ) ;
--
-- Then this code will raise the Storage_Error
--
begin
name := new String ( 1..256 ) ;
exception
when Storage_Error =>
Ada.Text_IO.Put_Line ( "Storage Error, 256" ) ;
end ;
--
-- This code will allocate the memory and assign it to "name"
--
begin
name := new String ( 1..100 ) ;
exception
when Storage_Error =>
Ada.Text_IO.Put_Line ( "Storage Error, 100" ) ;
end ;
--
-- Heap should have a size of 28 bytes
--
Ada.Text_IO.Put_Line ( "Heap Size = 28" ) ;
end ;
In <1189369871.672082.162750@50g2000hsm.googlegroups.com>, Maciej Sobczak <see.my.homepage@gmail.com> writes:
>On 9 Wrz, 14:17, a...@anon.org (anon) wrote:
>> For deallocation
>>
>> Recheck RM 13.11.2 Unchecked Storage Deallocation
>>
>> Paragragh (10) suggest that deallocation is guarantee, with
>> the exception if the object is a Task (9).
>
>You probably misunderstood me. I'm asking what will happen when the
>exception is raised when the allocator is evaluated.
>Consider:
>
>procedure P is
>
> type T (Init : Integer) is record
> C : Positive := Positive (Init);
> end record;
>
> type T_Access is access T;
>
> Ptr : T_Access;
>
>begin
> Ptr := new T (-5);
>exception
> when Constraint_Error =>
> -- is memory leaked or deallocated?
> null;
>end;
>
>I want to know whether the memory that was allocated for the new
>object was immediately deallocated due to the exception.
>By "immediately" I mean before the control even goes to the exception
>part.
>
>I don't find this guarantee anywhere in the AARM and it scares me.
>
>--
>Maciej Sobczak
>http://www.msobczak.com/
>
next prev parent reply other threads:[~2007-09-10 2:56 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 [this message]
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 ` Allocators and exceptions => Trying Again anon
2007-09-10 23:15 ` 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