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,89e4ceda6de0137b X-Google-Attributes: gid103376,public From: Matthew Heaney Subject: Re: About a conditional garbage collection Date: 1999/04/10 Message-ID: #1/1 X-Deja-AN: 464638521 References: <7elpap$9js$1@news1.bu.edu> NNTP-Posting-Date: Fri, 09 Apr 1999 18:31:21 PDT Newsgroups: comp.lang.ada Date: 1999-04-10T00:00:00+00:00 List-Id: 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. You can subscribe to the patterns list by sending the message (body) subscribe patterns to the ACM mailing-list server. > 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."