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.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Paul Rubin Newsgroups: comp.lang.ada Subject: Re: How to get Ada to ?cross the chasm?? Date: Thu, 03 May 2018 13:38:33 -0700 Organization: A noiseless patient Spider Message-ID: <87h8no1nli.fsf@nightsong.com> References: <1c73f159-eae4-4ae7-a348-03964b007197@googlegroups.com> <87k1su7nag.fsf@nightsong.com> <87po2la2qt.fsf@nightsong.com> <87in8buttb.fsf@jacob-sparre.dk> <87wowqpowu.fsf@nightsong.com> <16406268-83df-4564-8855-9bd0fe9caac0@googlegroups.com> <87o9i2pkcr.fsf@nightsong.com> <87in88m43h.fsf@nightsong.com> <87efiuope8.fsf@nightsong.com> <322f9b26-01de-4753-bb50-6ef2f3d993d8@googlegroups.com> <87a7th9pd1.fsf@nightsong.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: reader02.eternal-september.org; posting-host="9aa481526158253a2df1c34e89df6734"; logging-data="5391"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+m/oLQZlJsEsqZiMudzs0J" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) Cancel-Lock: sha1:MEe/F5hekCwpnHcwS2pm2m4FN8I= sha1:SxBeRfVSBg4YyP0gh+lVWCbwhZI= Xref: reader02.eternal-september.org comp.lang.ada:51946 Date: 2018-05-03T13:38:33-07:00 List-Id: gautier_niouzes@hotmail.com writes: > Which extra work do you expect without GC ? For example, in your "corporate bullshit generator" I see functions like: function Sentences (Possible_Dialog_Mark : String) return String is begin case R100 is when 1 .. 33 => -- Recursion stops in this case. Prob = p. return Sentence; when 34 .. 80 => return Sentences (Possible_Dialog_Mark) & Sentence; when 81 .. 100 => return Sentences (Possible_Dialog_Mark) & Paragraph_End_Mark & Paragraph_Mark & Possible_Dialog_Mark & Sentence; end case; end Sentences; This function appears to call itself recursively, generating a bunch of strings and concatenating them together. I'm not sure but it looks to me like these concatenations are done by copying the strings around, which is quite inefficient once the strings get large and the recursion gets deep. What the function is really generating is a tree structure, with nodes that can be expanded into further nodes or to sentences. So you should really represent those sentences as trees, where you print a sentence by traversing the tree recursively. You can do the same thing with job titles: they are really structures too. If Alice is the co-assistant-vice-president of whatever, then Alice's assistant would be the assistant-co-assistant-vice-president of whatever, and so on. She could have senior and junior assistants, co-assistants, and executive assistants, they'd have assistants of their own, etc. Now let's say Alice's job title is X (represented as a tree). She hires Bob as an assistant, so Bob's title is assistant-X. Bob's job title should be a node with a field saying "assistant" and a pointer to Alice's job title. The company directory has an entry for Alice containing her name and a pointer to her title, and a similarly entry for Bob. Note that Alice's title is a subtree of Bob's title, so they share structure in memory. Next, Alice leaves the company. Bob doesn't get a promotion (keeping in the spirit of your program, he's an assistant who happens to not assist anybody) and he is still in the directory. So you have to keep Alice's title around until all of her assistants have also left or been promoted or whatever. But then you have to free the memory, or else your program has a leak. There are various ways you can deal with this storage management issue. So you can think up a workable approach, implement and debug it, write regression tests and monitoring for it, etc. Or you can just not think about it at all, allocate new data whenever you want, and let GC take care of freeing it. I vote for GC :).