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 autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,3839fc233928a180 X-Google-Attributes: gid103376,public From: Pascal MALAISE Subject: Re: "free"ing allocated memory Date: 1997/12/16 Message-ID: <349642D6.EE653EDE@alphalink.com.au>#1/1 X-Deja-AN: 298646567 Content-Transfer-Encoding: 7bit References: <34693B2D.C53FFFC3@access.hky.com> <879660687.78snx@jvdsys.nextjk.stuyts.nl> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Organization: Alphalink Australia Newsgroups: comp.lang.ada Date: 1997-12-16T00:00:00+00:00 List-Id: Jerry van Dijk wrote: > > In article <34693B2D.C53FFFC3@access.hky.com> randyk@access.hky.com writes: > > >I allocate/create the new memory blocks with this routine.. But I cannot > >seem to figure out how to "free" the memory in Ada. > > > --this function creates a memory location and returns the address > > Node : P := new Link; --create new memory location > > Ada was developed with the possibility of garbage collection. Which means > the language system itself will reclaim the memory no longer in use. Much > like Java does. > > However, for several reasons (prominently embedded systems, real-time > systems and efficiency) most Ada compilers do not use it. > In this case the language offers the possibility of free-ing the memory > yourself, using Ada.Unchecked_Deallocation. As a type-safe language, > this procedure has to know what kind of memory it is suppossed to reclaim. > Therefor it is implemented as a generic procedure. Even if you are able to ask the OS to "free" memory, more and more OS (UNIX) wont release the associated swap space anyway. In some platforms, another approach than unchecked deallocation can be -- Allocates and frees cells of data access, -- using a free list to re-use free cells. generic type DATA_TYPE is private; type DATA_ACCESS_TYPE is access DATA_TYPE; package DYN_DATA is -- Allocates a new cell. -- The result is the access to a pre allocated area for DATA_TYPE. function ALLOCATE return DATA_ACCESS_TYPE; -- Allocates a new cell and fills it with DATA -- The result is the access to a pre allocated area for DATA_TYPE, -- storing DATA function ALLOCATE (DATA : DATA_TYPE) return DATA_ACCESS_TYPE; -- Frees a cell. DATA_ACCESS is set to null. procedure FREE (DATA_ACCESS : in out DATA_ACCESS_TYPE); end DYN_DATA; -- body available on demand -- Pascal MALAISE | E-mail: 52 Fletcher St | (priv) malaise@alphalink.com.au HAWTHORN EAST VIC 3123 | (prof) malaise@thomson.starway.net.au AUSTRALIA