comp.lang.ada
 help / color / mirror / Atom feed
From: murphy@mips.COM (Mike Murphy)
Subject: Re: C Strings in Ada?
Date: 11 Jun 90 22:30:52 GMT	[thread overview]
Message-ID: <39309@mips.mips.COM> (raw)
In-Reply-To: 57288@bbn.BBN.COM

In article <57288@bbn.BBN.COM> adoyle@vax.bbn.com (Allan Doyle) writes:
>When I am using the Ada "new" keyword, I know full well that I'm creating
>potential for garbage. I can control when I call it. I can write my own
>memory manager around it. I don't get that control when I need a construct
>like
>
>	declare
>		c_string : constant string := "foo" & ascii.nul;
>	begin
>		<stuff>
>	end;
>
>If I can't even trust Ada to reclaim the 4 or so bytes used by foo, what
>can I trust Ada to do????

Most Ada compilers will reclaim the space used by an object when it 
exits its scope.  I say "most" because this is not required by the 
semantics of the language, but any good compiler will have this feature, 
as it is needed for large software systems, and it is not too difficult
to implement.  Basically, you emit some code at the end of any blocks 
or statements that use temporary space, to reclaim that space.
This might mean a "free", or it could be something even cheaper 
(e.g. some compilers will put these kind of block-structured temporaries 
on a mark-release stack).  You can code up a little example like the above
to test what your compiler does.  This is not considered to be "real"
garbage-collection, which no Ada compiler I know of does, which requires
searching through memory for dangling pointers.  Instead this is just
an important optimization for a common situation in Ada.  The situation
is more common in Ada than in languages like C because we can have
function calls that return dynamic-sized objects, such as strings,
and these need temporary space.  The reclaiming of the space is helped
by the block-structured nature of its scope (as opposed to the
full-blown garbage collection problem).

-- Mike Murphy
-- UUCP: sun!decwrl!mips!murphy or murphy@mips.com

  parent reply	other threads:[~1990-06-11 22:30 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1990-06-04 22:45 C Strings in Ada? Andy DeFaria
1990-06-07 17:41 ` stt
1990-06-08 16:00 ` Andy DeFaria
1990-06-10 20:38   ` Alex Blakemore
1990-06-11 12:57     ` Allan Doyle
1990-06-11 14:59       ` David Kassover
1990-06-11 19:48         ` Allan Doyle
1990-06-11 21:01           ` David Kassover
1990-06-11 22:30           ` Mike Murphy [this message]
1990-06-13 21:20           ` Edward Falis
1990-06-11 17:53       ` David Emery
1990-06-11 19:59         ` Allan Doyle
1990-06-15  7:53   ` Jeff Bartlett
1990-06-11 22:39 ` Andy DeFaria
1990-06-12 14:04   ` David Emery
1990-06-12 18:11   ` Mike Murphy
1990-06-13 13:43 ` stt
replies disabled

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