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,70414f56d810c10c X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.27.231 with SMTP id w7mr557954pbg.7.1316661684643; Wed, 21 Sep 2011 20:21:24 -0700 (PDT) MIME-Version: 1.0 From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: discriminant questions Date: Wed, 21 Sep 2011 22:21:20 -0500 Organization: Jacob Sparre Andersen Research & Innovation Message-ID: References: <9f37b726-d80b-4d24-bf3f-28a14255f7fd@s20g2000yql.googlegroups.com> <86015926-d652-4265-aedd-413312d399f9@dq7g2000vbb.googlegroups.com> <0d272f62-67d0-4905-972c-8a7e912c5531@en1g2000vbb.googlegroups.com> <148cxoyabima2.16mz6xwdph2hj.dlg@40tude.net> <1b7pl1piwc3hl.7q9fyyq8h3m7.dlg@40tude.net> <3d49749a-1da5-49b9-bc68-5d9befb4ed62@hb5g2000vbb.googlegroups.com> <1gti2q424e3tt$.18e95xse1r7j8$.dlg@40tude.net> <862244d4-c7ca-4590-ac97-e2988ac27872@f8g2000yqf.googlegroups.com> <1rffjj30r3vtr.1ahkfeok7ia0w.dlg@40tude.net> NNTP-Posting-Host: static-69-95-181-76.mad.choiceone.net X-Trace: munin.nbi.dk 1316661683 4099 69.95.181.76 (22 Sep 2011 03:21:23 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Thu, 22 Sep 2011 03:21:23 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2900.6109 X-RFC2646: Format=Flowed; Original Path: lh7ni2270pbb.0!nntp.google.com!news1.google.com!news3.google.com!proxad.net!feeder1-2.proxad.net!feed.ac-versailles.fr!news.ecp.fr!news.jacob-sparre.dk!pnx.dk!jacob-sparre.dk!ada-dk.org!.POSTED!not-for-mail Xref: news1.google.com comp.lang.ada:18075 Date: 2011-09-21T22:21:20-05:00 List-Id: "Dmitry A. Kazakov" wrote in message news:1rffjj30r3vtr.1ahkfeok7ia0w.dlg@40tude.net... ... > Otherwise, I bet that a controlled accessor object would cost a lot more > than copying for almost all elements. Controlled types are very expensive. That's a myth. It's implementation-dependent of course, but they don't need to cost much at all. For Janus/Ada, they're a lot cheaper than returning an unconstrained String, for instance. Indeed, creating a controlled object costs three extra memory writes (a tag and two list entries), and finalizing it costs one dispatching call (which can be very cheap if the Finalize routine doesn't do anything). The call to the "Finalize_Objects" routine is inserted pretty much everywhere whether or not you use controlled types yourself, since Janus/Ada uses the same mechanisms for most tasking and memory management activities. And it is very cheap if there is nothing to do, as it is parameterless and consists of a single pointer compare in that case. The only legitimate complaint about finalization is the extra space needed for small objects, but even that isn't really that much. So the marginal runtime overhead for a controlled object is three memory writes on initialize, two on finalize, plus a dispatching call. This doesn't come close to "very expensive"; it's far less than the heap allocation needed to return an unconstrained string, for instance. And it should be noted that for limited controlled types in particular (which this is), you could do far better, generating the needed dispatching call directly in-line. (I know some AdaCore people were thinking about such an implementation in GNAT, I don't know if they ever implemented that.) Randy.