|
|
Warp wrote:
> Darren New <dne### [at] sanrrcom> wrote:
>> The whole "export template" bit I don't understand. I have to believe
>> that either there are restrictions on what a template can do and still
>> be able to be an export template, or there are bits in the object file
>> which are essentially getting recompiled at compile-time.
> object files is probably fairly trivial (because, after all, the object
> file has to have the original source code in one form or another inside
> it for the whole export template mechanism to be possible).
OK, that would be my second statement, then. The template is actually
getting recompiled down to object code each time you instantiate it,
even if it's an "export" template.
In a language like Ada (which has generics but not templates), you
compile the generic down to object code, and when you instantiate it,
you don't need the source for the implementations. I believe it can work
by basically, at instantiation time, building a descriptor not too
different from a vtable. If the only difference is which overloaded
functions get used, the object code will expect a table of pointers to
be created for it to invoke those functions. If it expects a different
size, then the object code is (possibly) duplicated and the size filled
in (just as you would fix up external references at link time), or the
code is slightly less efficient and takes as one parameter the size it
needs to work with.
In Java, of course, it compiles down to the same code as you would have
without generics, and you compile it once and ship the bytecodes. The
compiler basically just does error checking if the declaration is in
scope and casts the result of operations at runtime if so needed.
--
Darren New / San Diego, CA, USA (PST)
"That's pretty. Where's that?"
"It's the Age of Channelwood."
"We should go there on vacation some time."
Post a reply to this message
|
|