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=1.3 required=5.0 tests=BAYES_00,INVALID_MSGID, MSGID_RANDY autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,f1111f1bf805022b X-Google-Attributes: gid103376,public From: Ted Dennison Subject: Re: Unconstrained type Unchecked_Deallocation Date: 2000/03/06 Message-ID: <8a0h55$qc5$1@nnrp1.deja.com>#1/1 X-Deja-AN: 593766855 References: X-Http-Proxy: 1.0 x39.deja.com:80 (Squid/1.1.22) for client 204.48.27.130 Organization: Deja.com - Before you buy. X-Article-Creation-Date: Mon Mar 06 14:59:51 2000 GMT X-MyDeja-Info: XMYDJUIDtedennison Newsgroups: comp.lang.ada X-Http-User-Agent: Mozilla/4.7 [en] (WinNT; I) Date: 2000-03-06T00:00:00+00:00 List-Id: In article , Andy Askey wrote: > I have a byte array type that is used to generate byte-arrays > dynamically. I want to dynamically deallocate these byte-arrays. Can > I use the following to deallocate memory? > package tst_pkg is > type Byte_Atype is array (integer range <>) of character; > type Byte_Ptype is access Byte_Atype; > > procedure Free(The_Array : in out Byte_Ptype); > end tst_pkg; > > package body tst_pkg is > procedure Deallocate is new Ada.Unchecked_Deallocation( > Byte_Atype, Byte_Ptype); > > procedure Free(The_Array : in out Byte_Ptype) is > begin > Deallocate(The_Array); > end; > end tst_pkg; That ought to work just fine. However, I don't see the benifit of doing this over just naming the instantiation of Unchecked_Deallocation "Free" in the first place. They have the same parameter profile and the same mission. > The real question is will the Free procedure deallocate all the bytes > allocated with the following? > > my_bytes : Byte_Ptype; > begin > my_bytes := new Byte_Atype(1..100); > tst_pkg.Free(my_bytes); > end; Of course. If not, your compiler is seriously broken! -- T.E.D. http://www.telepath.com/~dennison/Ted/TED.html Sent via Deja.com http://www.deja.com/ Before you buy.