* Re: About a conditional garbage collection
1999-04-09 0:00 About a conditional garbage collection ddutheza
@ 1999-04-10 0:00 ` Matthew Heaney
1999-04-12 0:00 ` ddutheza
0 siblings, 1 reply; 3+ messages in thread
From: Matthew Heaney @ 1999-04-10 0:00 UTC (permalink / raw)
ddutheza@bu.edu (ddutheza) writes:
> This may be a classical question in Ada, but I just start with the
> language, so please escuse any stupid questions.
The only stupid question is the one that doesn't get asked.
> To begin, is there a possibility to include a conditional garbage
> collector in any Ada95 collector. By this, I mean a garbage collection
> that could be activated or not depending on the real-time constraints
> of a project?
I guess it depends on what you mean by "garbage collection." There is
no automatic garbage collector in the traditional sense, but what Ada does
is give you the programmer the tools you need to claim unused memory
automatically.
"Controlled" types in Ada automatically call operations during
elaboration, assignment, and finalization of a controlled object, which
can be used to reclaim garbage, or modify a reference-count.
So, for example, if I implement an unbounded stack as a controlled type,
I can reclaim the memory automatically when the stack object disappears.
So the garbage does indeed get collected.
I can even implement reference-counted lists this way. During
assignment of a list object, a count of references to the list is
incremented automatically.
When list objects are finalized, the reference count is decremented
automatically, and when it goes to zero, the list is garbage collected.
For an example of a reference-counted list, and many other examples,
visit the ACM patterns archive.
<http://www.acm.org/archives/patterns.html>
<mailto:patterns@acm.org>
You can subscribe to the patterns list by sending the message (body)
subscribe patterns <your full name>
to the ACM mailing-list server.
<mailto:listserv@acm.org>
> To finish, Modula-3 is like Ada95 a powerful programming language that
> could be use to create modern operating systems. One big advantage of
> modula are the modules that can be loaded and unloaded at run time
> making memeory management easier. Does Ada95 possess something similar
> to a module?
Ada has a module; it's called a "package."
^ permalink raw reply [flat|nested] 3+ messages in thread