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!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Ada Annoyances Date: Sat, 24 Jun 2017 17:40:38 +0200 Organization: Aioe.org NNTP Server Message-ID: References: <1ac5a44b-4423-443a-a7bb-2864d9abe78f@googlegroups.com> <1498048151.20885.28.camel@obry.net> <96174ea5-852d-44e9-8535-7c1eb24d5326@googlegroups.com> <8d3aff06-82df-485f-89e5-a50c326aab05@googlegroups.com> <66aa262e-2ac9-4016-b32d-e9fee14779e1@googlegroups.com> <88e2f18a-0786-4303-a5b8-fe82e8c81dcb@googlegroups.com> <357b04d6-d00d-42e4-aebe-af1270f96efb@googlegroups.com> NNTP-Posting-Host: MajGvm9MbNtGBKE7r8NgYA.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 X-Notice: Filtered by postfilter v. 0.8.2 Content-Language: en-US Xref: news.eternal-september.org comp.lang.ada:47100 Date: 2017-06-24T17:40:38+02:00 List-Id: On 2017-06-24 15:06, pythoner6@gmail.com wrote: > As I understand it, the penalty in Ada is going to some extra space > for the tag (how big is this? I haven't found much info on the size > of a tag, which I'm assuming is because this may be implementation > dependent?), Do this: type Empty is tagged null record; Empty'Size is the size in bits. > and the smart pointer will get passed around by reference, as > opposed to by value which would make more sense. While for most part > I'm not too concerned about the extra space required for the tag (in other cases), > for a smart pointer that's probably about doubling the size which is > unfortunate. That depends. Pointers to reference-counted objects are much better to passed by reference. Because by-copy passing will require incrementing and decrementing the reference count, which in concurrent environment requires expensive locking. The sorts of pointers usually passed by copy are normally superfluous in Ada. > Method calls won't be dynamically dispatched unless you're dealing > with a Smart_Pointer'Class and calling methods that take a Smart_Pointer > (which I don't see much reason to do if you want a low overhead smart > pointer), right? Wrong. In Ada a pointer need not to be tagged in order to dispatch on the target. type T is tagged ... procedure Foo (X : in out T); type S is new T with ... type Pointer is access T'Class; X : Pointer := new S; X.Foo -- This dispatches >> In C++ when the object of derived class is constructed, its base >> class constructor is called first and at that time the object is >> considered to have the Base dynamic type [...] >> In this sense and this particular context, C++ offers better and >> stronger (!) type safety than Ada. > Ah, I see. An object may not change its type. When not constructed it simply does not exist. C++ construction model is safer where it supports user-defined hooks for specific types. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de