comp.lang.ada
 help / color / mirror / Atom feed
From: Pascal MALAISE <malaise@alphalink.com.au>
Subject: Re: "free"ing allocated memory
Date: 1997/12/16
Date: 1997-12-16T00:00:00+00:00	[thread overview]
Message-ID: <349642D6.EE653EDE@alphalink.com.au> (raw)
In-Reply-To: 879660687.78snx@jvdsys.nextjk.stuyts.nl


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




  reply	other threads:[~1997-12-16  0:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-11-12  0:00 "free"ing allocated memory Randy Kosarik
1997-11-16  0:00 ` Jerry van Dijk
1997-12-16  0:00   ` Pascal MALAISE [this message]
1997-11-18  0:00 ` Stephen Leake
replies disabled

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