Template instantiation
Jarrett Billingsley
jarrett.billingsley at gmail.com
Fri Mar 20 10:31:13 PDT 2009
On Fri, Mar 20, 2009 at 11:35 AM, Trass3r <mrmocool at gmx.de> wrote:
> Got the following code:
>
> public LuaState wrapClass (T) (T instance)
> {
> auto ptr = cast (T *) newUserdata ( (T *).sizeof);
> *ptr = instance;
>
> loadClassMetatable (typeid(T).toString);
> setMetatable (-2);
> return this;
> }
>
> Am I right in assuming that a different wrapClass will be created in the
> final executable for each template instantiation (e.g. calls with class
> A,B,C,... instances) and would thus bloat up the executable a bit when used
> with many classes?
Yes.
> Apart from that, couldn't you just use wrapClass (Object instance)? In the
> end each class instance pointer takes up the same amount of memory?!
>
I'd say yes. It doesn't look like there's any need for a template here.
It wouldn't be (Object*).sizeof when allocating the userdata, though;
just Object.sizeof.
More information about the Digitalmars-d-learn
mailing list