comp.lang.ada
 help / color / mirror / Atom feed
From: Marin David Condic <nobody@noplace.com>
Subject: Re: Variant vs. Tagged Type
Date: Wed, 05 Nov 2003 12:49:05 GMT
Date: 2003-11-05T12:49:05+00:00	[thread overview]
Message-ID: <3FA8F1B8.9070408@noplace.com> (raw)
In-Reply-To: oprx5zpwdbz12uz9@news.onlinehome.de

Well, in most respects, a tagged type is just a special case of a 
variant record. (Conceptually) The "variant" is the tag. In that sense, 
most access should be just as fast either way - depending on compilers 
and optimizations, etc. (The only way to know for sure is to measure 
with *your* compiler in *your* environment with code that is typical of 
what you want to do. Maybe Ada should develop a performance benchmark 
suite to test some of these things?)

However, you do have to be careful with tagged types in that some things 
cannot be done statically at compile-time. Things like dispatching to 
operations on the tagged type. In general, the static things should be 
no worse than any other sort of operation on a variant record, but if 
you use features that are dynamic, you'll incur some additional 
overhead. (How much? You can only know by checking into your compiler.)

OTOH, you also need to ask just how critical the time concerns are. In 
many apps, the slight additional overhead connected to tagged types is 
not enough to cause any sort of problem. In other apps, you might be so 
tight on the time budget that even the variant record approach might be 
too much to bear. (The code has to look up the variant at run time to 
know how to interpret the record, right? That's not free.) Lots of 
designers get their panties in a bunch over performance concerns when a 
step back and a deep breath reveals its all "the small stuff." Like life 
in general, we often worry about things that never happen.

MDC


Frank Piron wrote:
> Hi,
> is it possible to make some general statements
> concerning the alternative variant vs. tagged
> type with respect to runtime performance?
> For example:
> if we have an array A 1) of type access to a variant
> 2) of type access <TYPE>'Class
> what can be said about the runtime performance
> of the expression
> A(I).<component>?
> Thanks in Advance,
> Frank
> 


-- 
======================================================================
Marin David Condic
I work for: http://www.belcan.com/
My project is: http://www.jsf.mil/NSFrames.htm

Send Replies To: m   o   d   c @ a   m   o   g
                    c   n   i       c   .   r

     "So if I understand 'The Matrix Reloaded' correctly, the Matrix is
     basically a Microsoft operating system - it runs for a while and
     then crashes and reboots. By design, no less. Neo is just a
     memory leak that's too hard to fix, so they left him in... The
     users don't complain because they're packed in slush and kept
     sedated"

         --  Marin D. Condic
======================================================================




  reply	other threads:[~2003-11-05 12:49 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-11-05 12:30 Variant vs. Tagged Type Frank Piron
2003-11-05 12:49 ` Marin David Condic [this message]
2003-11-05 14:50 ` Steve
2003-11-05 17:40 ` Jeffrey Carter
2003-11-06  7:22   ` Frank Piron
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox