Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Ada > Re: Generics wi...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 8 of 11 Topic 5629 of 5831
Post > Topic >>

Re: Generics with concrete and class-wide types

by "Dmitry A. Kazakov" <mailbox@[EMAIL PROTECTED] > Apr 1, 2008 at 11:42 AM

On Mon, 31 Mar 2008 13:22:10 -0700 (PDT), Maciej Sobczak wrote:

> Consider a generic subprogram that makes sense for arguments of both
> class-wide type and a concrete type.
> 
> As a motivating example, there might be a hierarchy of iterator types
> rooted in some imaginary Iterator type that is itself defined in the
> generic package with the element type as its own formal parameter.
> There are concrete iterator types that are derived from this root
> Iterator type (exactly: from some instantiation thereof).
> 
> There might be also a generic subprogram that operates on the iterator
> given as its parameter. This subprogram takes two formal generic
> parameters: the element type and the iterator type.
> 
> Now - on one hand it makes sense to have a hierarchy of iterators and
> benefit from loose coupling and other features of OO, but on the other
> hand the iterators themselves can be lightweight objects that are used
> in tight loops and we can expect them to be fast, therefore we could
> benefit from *avoiding* the dynamic dispatch if there is enough
> context to do so.
>
> Both make sense, depending on the context at the call site.
> 
> To achieve both benefits the user might instantiate the subprogram for
> the Iterator'Class type (to be exact: for the 'Class of some
> instantiation of Iterator) in the context where only a class-wide type
> is available, like within some other polymorphic subprogram; and for
> the concrete type, like My_Concrete_Iterator, in the context where the
> concrete type is available, with the hope that such an instantiation
> can be more easily inlined.

Just a small side note. If you care about performance you should do
exactly
the opposite you tried to, i.e. you should instantiate it with a specific
type rather than with a class of. Doing so, you will force the compiler to
resolve primitive operations statically without dispatching overhead. When
you use class-wide, then its will dispatch somewhere, maybe later in the
bodies, maybe more than once.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
 




 11 Posts in Topic:
Generics with concrete and class-wide types
Maciej Sobczak <see.my  2008-03-31 13:22:10 
Re: Generics with concrete and class-wide types
Adam Beneschan <adam@[  2008-03-31 16:38:41 
Re: Generics with concrete and class-wide types
"Randy Brukardt"  2008-04-01 15:10:13 
Re: Generics with concrete and class-wide types
"Randy Brukardt"  2008-03-31 19:23:03 
Re: Generics with concrete and class-wide types
Eric Hughes <eric.eh9@  2008-03-31 20:57:57 
Re: Generics with concrete and class-wide types
christoph.grein@[EMAIL PR  2008-03-31 23:58:59 
Re: Generics with concrete and class-wide types
Georg Bauhaus <rm.tsoh  2008-04-01 09:22:56 
Re: Generics with concrete and class-wide types
"Dmitry A. Kazakov&q  2008-04-01 11:42:18 
Re: Generics with concrete and class-wide types
Maciej Sobczak <see.my  2008-04-01 02:51:19 
Re: Generics with concrete and class-wide types
"Dmitry A. Kazakov&q  2008-04-01 12:53:04 
Re: Generics with concrete and class-wide types
Adam Beneschan <adam@[  2008-04-01 14:17:56 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 20:50:21 CDT 2008.