comp.lang.ada
 help / color / mirror / Atom feed
* Ada memory management?
@ 2004-10-07  9:39 matthias_k
  2004-10-07 12:06 ` Martin Krischik
  2004-10-07 17:24 ` Nick Roberts
  0 siblings, 2 replies; 18+ messages in thread
From: matthias_k @ 2004-10-07  9:39 UTC (permalink / raw)


Hey there,

since there is an allocator 'new' in Ada, I was wondering if there is a 
'delete' too. I've heard there is a special technique called Storage 
Pool in Ada to write own memory managers, but what is the default 
deallocator?

Consider this code:

procedure Does_This_Leak is
    type Int_Ptr is access Integer;
    ptr: Int_Ptr;
begin
    ptr := new Integer;
end Does_This_Leak;

Will this procedure leak? Or does Ada somehow deal on its own with the 
allocation.

Thanks in advance,
Matthias



^ permalink raw reply	[flat|nested] 18+ messages in thread
* Re: Ada memory management?
@ 2004-10-07 10:00 Christoph Karl Walter Grein
  2004-10-07 10:41 ` Stephen Thomas
  2004-10-07 12:00 ` Martin Krischik
  0 siblings, 2 replies; 18+ messages in thread
From: Christoph Karl Walter Grein @ 2004-10-07 10:00 UTC (permalink / raw)
  To: comp.lang.ada

procedure Does_This_Leak is
    type Int_Ptr is access Integer;
    ptr: Int_Ptr;
begin
    ptr := new Integer;
end Does_This_Leak;

Of course this leaks, and imagine how much!

Consider Ada.Unchecked_Deallocation. It's called Unchecked because it's your very chore to take care of not
producing dangling pointers.
________________________________________________________________
Verschicken Sie romantische, coole und witzige Bilder per SMS!
Jetzt neu bei WEB.DE FreeMail: http://freemail.web.de/?mc=021193




^ permalink raw reply	[flat|nested] 18+ messages in thread
* Re: Ada memory management?
@ 2004-10-07 11:15 Christoph Karl Walter Grein
  2004-10-07 12:01 ` Stephen Thomas
  0 siblings, 1 reply; 18+ messages in thread
From: Christoph Karl Walter Grein @ 2004-10-07 11:15 UTC (permalink / raw)
  To: comp.lang.ada

Stephen Thomas:
> > procedure Does_This_Leak is
> >     type Int_Ptr is access Integer;
> >     ptr: Int_Ptr;
> > begin
> >     ptr := new Integer;
> > end Does_This_Leak;
> > 
> > Of course this leaks, and imagine how much!
> 
> Actually, no it shouldn't, not on a halfway-decent implementation.
> Logically speaking, a storage pool for items accessed via values of
> an access type has the same lifetime as the access type itself. In
> the above example, a new storage pool for Int_Ptr is created on
> entry to Does_This_Leak, and is removed on exit.

RM 13.11(17) If Storage_Pool is not specified ... then the implementation chooses a standard storage pool .. in an implementation-defined manner.

So how do you arrive at this statement?

But see RM 13.11(18): The case is different if a Storage_Size is defined.
__________________________________________________________
Mit WEB.DE FreePhone mit hoechster Qualitaet ab 0 Ct./Min.
weltweit telefonieren! http://freephone.web.de/?mc=021201




^ permalink raw reply	[flat|nested] 18+ messages in thread
* Re: Ada memory management?
@ 2004-10-07 11:31 Christoph Karl Walter Grein
  0 siblings, 0 replies; 18+ messages in thread
From: Christoph Karl Walter Grein @ 2004-10-07 11:31 UTC (permalink / raw)
  To: comp.lang.ada

Jeff C r e e.m:
> > Actually, no it shouldn't, not on a halfway-decent implementation.
> > Logically speaking, a storage pool for items accessed via values of
> > an access type has the same lifetime as the access type itself. In
> > the above example, a new storage pool for Int_Ptr is created on
> > entry to Does_This_Leak, and is removed on exit.
> >
> > Stephen
> > -- 
> 
> 
> Stephen is correct...But just to be clear (because this is where people (not 
> Stephen) get confused is that the following
> (much more common construct) would leak unless unchecked_deallocation is 
> used.

No, he isn't, see my previous post! To get this effect, you have to define Storage_Size or a local storage pool.

> package body Like_A_Sieve is
> 
>      type Int_Ptr is access Integer;
> 
> procedure Does_This_Leak is
>      ptr: Int_Ptr;
> begin
>      ptr := new Integer;
>  end Does_This_Leak;
> 
> end Like_A_Sieve;

But your example is also correct.
__________________________________________________________
Mit WEB.DE FreePhone mit hoechster Qualitaet ab 0 Ct./Min.
weltweit telefonieren! http://freephone.web.de/?mc=021201




^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2004-10-09  0:12 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-07  9:39 Ada memory management? matthias_k
2004-10-07 12:06 ` Martin Krischik
2004-10-07 17:24 ` Nick Roberts
2004-10-07 19:04   ` Luke A. Guest
2004-10-07 22:52     ` ECLAT [was: Ada memory management?] Nick Roberts
2004-10-08 18:16       ` Luke A. Guest
2004-10-09  0:12         ` Nick Roberts
  -- strict thread matches above, loose matches on Subject: below --
2004-10-07 10:00 Ada memory management? Christoph Karl Walter Grein
2004-10-07 10:41 ` Stephen Thomas
2004-10-07 11:17   ` Jeff C r e e.m
2004-10-07 14:22   ` Georg Bauhaus
2004-10-07 14:51     ` Stephen Thomas
2004-10-07 16:23     ` Larry Kilgallen
2004-10-07 18:35       ` Frank J. Lhota
2004-10-07 12:00 ` Martin Krischik
2004-10-07 11:15 Christoph Karl Walter Grein
2004-10-07 12:01 ` Stephen Thomas
2004-10-07 11:31 Christoph Karl Walter Grein

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