From: optikos@verizon.net
Subject: Re: Generics vs. O-O?
Date: Thu, 1 Aug 2013 13:10:39 -0700 (PDT)
Date: 2013-08-01T13:10:39-07:00 [thread overview]
Message-ID: <fdf94891-3258-480d-a203-c157559e928f@googlegroups.com> (raw)
In-Reply-To: <1wugpqyea6s39$.e2e8eshup5wn$.dlg@40tude.net>
On Thursday, August 1, 2013 2:24:57 PM UTC-5, Dmitry A. Kazakov wrote:
> [... snip ...]
> 5. Considering run-time effects generics obviously have none because it is
> static polymorphism.
> [... snip ...]
Not so fast. Your statement on your #5 is true for C++ templates, but not true for Ada generics. The difference is that instantiations by different combinations of template-parameters of a C++ template result in a combinatorial explosion of the quantity of instances of that template's machine code & static data.
Conversely, Ada utilizes a single instance of machine code & static data for an Ada generic, regardless of the type parameters passed at compile-time. This single instance of machine-code accommodates different type parameters by either branching (around different per-type-parameter treatment) or table look-up (of the size & structure of entities). No such branching or table-lookup is present in the corresponding combinatorial explosion of C++ template instantiation. This conflation by branching or table look-up in Ada is precisely why the combinatorial explosion does not occur in Ada generics, as it does in C++ templates.
Hence, Ada's branching and table-lookups will in fact incur some execution-time overhead when compared to analogous C++ templates and when compared to nongeneric equivalent functionality. Conversely, when looking at code bloat, Ada's generics will incur some executable-size space overhead when compared to nongeneric equivalent functionality, but both the Ada generic and the nongeneric equivalent functionality will result in drastically smaller executables than a (naïvely-designed) C++ template that is instantiated with a vast quantity of combinations of parameters to that C++ template. Hence, in C++, the best-practice is to manually design a C++ template whose nontemplated guts accomplishes the conflation that the Ada compiler performs for an Ada generic. In C++ this often means that a type-safe C++ template thinly ricochets off to a nontemplate/nongeneric functionality that utilizes void* & corresponding sizeof to defeat all type-safety of objects or scalars.
next prev parent reply other threads:[~2013-08-01 20:10 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-01 14:45 Generics vs. O-O? Eryndlia Mavourneen
2013-08-01 19:24 ` Dmitry A. Kazakov
2013-08-01 19:52 ` Eryndlia Mavourneen
2013-08-01 20:14 ` sbelmont700
2013-08-01 23:35 ` Yannick Duchêne (Hibou57)
2013-08-01 20:10 ` optikos [this message]
2013-08-01 20:26 ` Dmitry A. Kazakov
2013-08-01 20:35 ` Jeffrey Carter
2013-08-01 21:22 ` Bill Findlay
2013-08-01 23:38 ` Yannick Duchêne (Hibou57)
2013-08-01 22:20 ` Georg Bauhaus
2013-08-02 8:11 ` Dmitry A. Kazakov
2013-08-02 9:50 ` Georg Bauhaus
2013-08-02 14:09 ` Dmitry A. Kazakov
2013-08-02 15:08 ` Shark8
2013-08-02 15:36 ` Alan Jump
2013-08-02 17:00 ` Jeffrey Carter
2013-08-02 17:51 ` Dmitry A. Kazakov
2013-08-02 18:06 ` Alan Jump
2013-08-02 19:08 ` Dmitry A. Kazakov
2013-08-02 16:15 ` Dmitry A. Kazakov
2013-08-03 0:04 ` Yannick Duchêne (Hibou57)
2013-08-03 7:35 ` Georg Bauhaus
2013-08-03 8:57 ` Dmitry A. Kazakov
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox