From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC,T_FILL_THIS_FORM_SHORT autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,6b1a1ed8b075945 X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news2.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!wn13feed!worldnet.att.net!bgtnsc05-news.ops.worldnet.att.net.POSTED!53ab2750!not-for-mail Newsgroups: comp.lang.ada From: anon@anon.org (anon) Subject: Re: Allocators and exceptions Reply-To: anon@anon.org (anon) References: <1189323618.588340.87180@o80g2000hse.googlegroups.com> <1189369871.672082.162750@50g2000hsm.googlegroups.com> X-Newsreader: IBM NewsReader/2 2.0 Message-ID: Date: Mon, 10 Sep 2007 02:56:36 GMT NNTP-Posting-Host: 12.64.96.6 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc05-news.ops.worldnet.att.net 1189392996 12.64.96.6 (Mon, 10 Sep 2007 02:56:36 GMT) NNTP-Posting-Date: Mon, 10 Sep 2007 02:56:36 GMT Organization: AT&T Worldnet Xref: g2news2.google.com comp.lang.ada:1855 Date: 2007-09-10T02:56:36+00:00 List-Id: 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 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/ >