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=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,f2690a5e963b61b6 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.freenet.de!koehntopp.de!news2.volia.net!news2.dg.net.ua!news.alkar.net!not-for-mail From: Maxim Reznik Newsgroups: comp.lang.ada Subject: Re: GCC 4.0 Ada.Containers Cursor danger. Date: Wed, 06 Jul 2005 16:57:16 +0300 Organization: Alkar Teleport News Server Message-ID: References: <1120474891.635131.216700@g44g2000cwa.googlegroups.com> <42C98672.3020705@arcor.de> <42cbb631$0$10808$9b4e6d93@newsread4.arcor-online.net> NNTP-Posting-Host: 213.154.193.74 Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: pandora.alkar.net 1120658236 94511 213.154.193.74 (6 Jul 2005 13:57:16 GMT) X-Complaints-To: abuse@alkar.net NNTP-Posting-Date: Wed, 6 Jul 2005 13:57:16 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.6) Gecko/20050402 X-Accept-Language: ru, en-us, en In-Reply-To: <42cbb631$0$10808$9b4e6d93@newsread4.arcor-online.net> X-Enigmail-Version: 0.90.2.0 X-Enigmail-Supports: pgp-inline, pgp-mime Xref: g2news1.google.com comp.lang.ada:11897 Date: 2005-07-06T16:57:16+03:00 List-Id: Georg Bauhaus wrote: > Maxim Reznik wrote: > >> I agree with Dmitry such behavior of Cursors is very dangerous >> and should be avoided. > > > That's what Matthew has said: You don't have to use > Cursors with maps. The library is generous enough to > provide Cursors, should you need them for some reason. > I mean it should be avoided by Ada (by standard), not by the user. >> If container knows all his cursors it can do it easy. > > The knowledge + checking results in performance loss. > >> There are a very few cursors per container in typical program, >> so it is not big work. > > > Care to give some data? It is difficult to argue about > hot air. > I look in all my Ada programs. There are a few loops per container, no more that 2 or 3 at once. Because cursors's main purpose is iteration over containers I think there will be a few cursors per container usually. If make container remember all its cursors we can implement all operations which make cursors invalid so that they reset invalid cursors to No_Element. For instance, Remove will iterate over all cursors for the container, check target of cursor and set cursor to No_Element if target match removed element. >> And safety here is much important then performacne. > > > Sometimes performance is a *requirement* for achieving > safety, there is no trade-off between speed and checking > access then. E.g. response time must be within some limit, > therefore the container algorithm must work within > O(the-function-here). > The method I propose costs O(cursors per container) performance penalty. I think it's acceptable cost for safety. If we should choise between safe and good performance Ada containers I would choose safe ones. In rare cases when user encounter performace limits he could easy implement his own container, with limited functionality. And he will know exactly where dangling references cound apear. Now cursor is like grenade. You don't know what happens if you use it. Because you can't check is it valid cursor. Even objects imported form other language are safer, because you can check them with 'Valid attribute before use them. > > Georg