comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Curiosity in generic package instantiation
Date: Thu, 21 Aug 2014 17:39:51 -0500
Date: 2014-08-21T17:39:51-05:00	[thread overview]
Message-ID: <lt5sfn$u0l$1@loke.gir.dk> (raw)
In-Reply-To: f9998a20-46fd-492a-b8a3-02105f728e82@googlegroups.com

"Adam Beneschan" <adambeneschan@gmail.com> wrote in message 
news:f9998a20-46fd-492a-b8a3-02105f728e82@googlegroups.com...
...
>An implementation can do either.  Suppose you instantiate 
>Ada.Containers.Doubly_Linked_Lists
> with multiple types in the same program:
>
>    package Example_Pkg is new 
> Ada.Containers.Doubly_Linked_List(Example_Type);
>    package Another_Pkg is new 
> Ada.Containers.Doubly_Linked_List(Another_Type);
>    package A_Third_Pkg is new Ada.Containers.Doubly_Linked_List(Type_3);
>
> If you compile with GNAT, you'll get three copies of the 
> Doubly_Linked_List code, with
> each copy set up to work on a different type.  If you compile with Janus 
> Ada, you will get
> only one copy of the code.  I'm not entirely sure what the code looks 
> like, but probably
> when the subprograms in the instantiation are called, they will be given a 
> parameter that
> contains some information needed about each type, such as the size of the 
> type, so that
> the code in the instantiation will know what to do when copying objects of 
> the type
> around.  I'm assuming this approach takes less code space but performs a 
> little slower.

The run-time cost (if any) depends mainly on the type of formal parameter. 
For formal private types, the code is almost the same as it would have been 
anyway (assignments and initializations being done about the same as they 
would have anyway, especially if the actual type is some sort of record). 
(There's a small cost for declared objects as they need an extra level of 
indirection.) Similarly, the various formal scalar types are not much 
impacted. OTOH, some of the lesser used formal parameters have a larger cost 
(in code and space).

Our original plan was to use automatic inlining to reduce these costs (it's 
a lot easier to unshare code that was compiled to be shared than it is to 
share code that was compiled separately -- we did the latter for our Z-80 
CP/M compilers, but it didn't work at all on the 8086 processors). We never 
got around to implementing that (in part because it required larger hosts 
than were common back in the day, and now there is a long list of other 
things that are more important), so it's hard to say how well that would 
have worked.

                                                 Randy.


  parent reply	other threads:[~2014-08-21 22:39 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-19 22:26 Curiosity in generic package instantiation GianLuigi Piacentini
2014-08-19 23:16 ` Adam Beneschan
2014-08-20  8:56   ` Mark Lorenzen
2014-08-21 22:32     ` Randy Brukardt
2014-08-21 22:39   ` Randy Brukardt [this message]
2014-08-20  7:18 ` Björn Lundin
replies disabled

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