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!news.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: "Alejandro R. Mosteo" Newsgroups: comp.lang.ada Subject: Re: Getting the index for an element in mutually referencing containers Date: Mon, 13 Mar 2017 11:29:25 +0100 Organization: A noiseless patient Spider Message-ID: References: <86o9xa36oq.fsf@gaheris.avalon.lan> <86k27xpikd.fsf@gaheris.avalon.lan> <86wpbxneuz.fsf@gaheris.avalon.lan> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Mon, 13 Mar 2017 10:26:35 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="5754d27883855088bf1d7fd5cad7a2c0"; logging-data="15803"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+P/d0ETRkmSutCRiyjGQfQ" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0 In-Reply-To: Cancel-Lock: sha1:NYVQPZzBtmVlwpwI+eiuVW4fyqc= Xref: news.eternal-september.org comp.lang.ada:28132 Date: 2017-03-13T11:29:25+01:00 List-Id: On 12/03/17 09:22, Simon Wright wrote: > Niklas Holsti writes: > >> On 17-03-11 23:46 , Simon Wright wrote: >> >>> Basically, I (Simon, now) am having trouble thinking of an >>> application where reference counting would be an appropriate >>> solution. >> >> How about this one: the SW generates messages (telemetry packets) >> reporting various sorts of data and events. >> > [...] >> >> Each destination has a queue of incoming messages, and the queueing >> and processing time for a given message varies accordingly. Rather >> than copy the (possibly long) message into each destination's queue, >> the queues hold references to a single, shared instance of the >> message, dynamically allocated in a memory pool. These references are >> counted. When, finally, all destinations have processed the message, >> the message's reference count reaches zero, and the message can be >> deallocated. >> >> This use of reference counting is a typical design in satellite >> on-board SW. > > Thanks for the example! > > I still have a feeling that this is an in-computer software technique > which resolves a software problem, rather than a necessary response to > an application-domain problem. This is how (most? I can only vouch for Java) garbage-collecting languages work. Thus is a common way of thinking for many programmers (I would say most think first of ref-counted ptrs before weak refs when faced with the problem being discussed, but that's just my impression). And the source of a kind of memory leak, which is the problem you get in exchange for no dangling pointers... Not surprisingly, C++ has standardized the whole shebang, with both semantics being discussed here covered: http://en.cppreference.com/w/cpp/memory Alex.