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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.224.4.138 with SMTP id 10mr8587811qar.8.1377847757938; Fri, 30 Aug 2013 00:29:17 -0700 (PDT) X-Received: by 10.49.70.138 with SMTP id m10mr13135qeu.9.1377847757920; Fri, 30 Aug 2013 00:29:17 -0700 (PDT) Path: border1.nntp.dca3.giganews.com!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!fx3no6156675qab.0!news-out.google.com!he10ni3964qab.0!nntp.google.com!fx3no6156671qab.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Fri, 30 Aug 2013 00:29:17 -0700 (PDT) In-Reply-To: <66f24ada-122c-4c01-9f04-5bc92233a456@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=136.163.203.9; posting-account=l8k8IwoAAADeDydswOzwNzmn10qOk9gt NNTP-Posting-Host: 136.163.203.9 References: <66f24ada-122c-4c01-9f04-5bc92233a456@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Anonymous access types are evil, why? From: ake.ragnar.dahlgren@gmail.com Injection-Date: Fri, 30 Aug 2013 07:29:17 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Original-Bytes: 3758 Xref: number.nntp.dca.giganews.com comp.lang.ada:183221 Date: 2013-08-30T00:29:17-07:00 List-Id: On Wednesday, August 28, 2013 6:10:15 PM UTC+2, Adam Beneschan wrote: > On Wednesday, August 28, 2013 4:49:56 AM UTC-7, ake.ragna...@gmail.com wr= ote: > Consider the following application that uses anonymous access types = and allocates Controlled objects on the heap using two different ways. One = way takes 60 times longer than the other: [rest snipped] I get the same res= ults with GNAT 2012, but not GNAT 2011. Also, there were some rule changes = in Ada 2012 with respect to allocators whose type is an anonymous access ty= pe, which is what you're dealing with when you assign B.A in Direct_Assignm= ent. A cursory reading of 3.10.2(14/3) makes me think that none of the rule= changes should apply in this case, but I don't know. (Yes, I'm aware that = "cursory reading" and "3.10.2" should never appear together in the same sen= tence.) So I'd guess that the overhead is due to the way GNAT changed its i= mplementation to deal with the new rules. Whether it did so correctly or no= t, I can't say. I'm not familiar enough with the ramifications of the new r= ules to have any idea what kind of implementation overhead they may require= , and I'm not a GNAT developer in any case. > What are the conclusions we c= an draw? > > 1. Perhaps one conclusion would be that when using anonymous a= ccess types then indirect assignment should be preferred over direct assign= ment. (see Models.B.Direct_Assignment and Models.B.Indirect_Assignment). Mo= re the the point, this probably means "an allocator whose type is a named a= ccess type should be preferred over an allocator whose type is anonymous". = I found that even if B_Type.A is declared as an anonymous access type, putt= ing this in Direct_Assignment: B.A :=3D Models.A.A_Access_Type' (new Models= .A.A_Type); eliminates the huge difference in execution time, because now t= he allocator is not returning an anonymous access type. > 2. Avoid anonymou= s access types. Prefer named access types and 'Unchecked_Access. I hope we = don't have to draw this conclusion. It would be sad if, with our right hand= , we're urging people to adopt Ada because of its safety, and then with our= left hand we recommend that they use 'Unchecked_Access and defeat the safe= ty mechanism. -- Adam Thanks for your analysis and especially the interesting result "an allocato= r whose type is a named access type should be preferred over an allocator w= hose type is anonymous". Best regards, =C5ke Ragnar Dahlgren