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.66.162.134 with SMTP id ya6mr8046499pab.7.1377706216049; Wed, 28 Aug 2013 09:10:16 -0700 (PDT) X-Received: by 10.50.16.111 with SMTP id f15mr484187igd.2.1377706215778; Wed, 28 Aug 2013 09:10:15 -0700 (PDT) Path: border1.nntp.ams.giganews.com!nntp.giganews.com!newsfeed.fsmpi.rwth-aachen.de!news.glorb.com!pt2no37240274pbb.0!news-out.google.com!z6ni21374pbu.0!nntp.google.com!fx3no5882356qab.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Wed, 28 Aug 2013 09:10:15 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=66.126.103.122; posting-account=RxNzCgoAAACA5KmgtFQuaU-WaH7rjnAO NNTP-Posting-Host: 66.126.103.122 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <66f24ada-122c-4c01-9f04-5bc92233a456@googlegroups.com> Subject: Re: Anonymous access types are evil, why? From: Adam Beneschan Injection-Date: Wed, 28 Aug 2013 16:10:15 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Xref: number.nntp.dca.giganews.com comp.lang.ada:183200 Date: 2013-08-28T09:10:15-07:00 List-Id: On Wednesday, August 28, 2013 4:49:56 AM UTC-7, ake.ragna...@gmail.com wrot= e: > Consider the following application that uses anonymous access types and a= llocates Controlled objects on the heap using two different ways. One way t= akes 60 times longer than the other: [rest snipped] I get the same results 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 type, which is what you're dealing with when you assign B.= A in Direct_Assignment. A cursory reading of 3.10.2(14/3) makes me think t= hat 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 tog= ether in the same sentence.) So I'd guess that the overhead is due to the = way GNAT changed its implementation to deal with the new rules. Whether it= did so correctly or not, I can't say. I'm not familiar enough with the ra= mifications of the new rules to have any idea what kind of implementation o= verhead they may require, and I'm not a GNAT developer in any case. > What are the conclusions we can draw? >=20 > 1. Perhaps one conclusion would be that when using anonymous access types= then indirect assignment should be preferred over direct assignment. (see = Models.B.Direct_Assignment and Models.B.Indirect_Assignment). More the the point, this probably means "an allocator whose type is a named= access 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, p= utting 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 the allocator= is not returning an anonymous access type. > 2. Avoid anonymous 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 th= en with our left hand we recommend that they use 'Unchecked_Access and defe= at the safety mechanism. -- Adam