"Cool Guy" <co*****@abc.xyz> wrote in message
news:15****************@cool.guy.abc.xyz...
I don't understand the third paragraph under the heading 'Generic type
instantiations' on
<http://msdn.microsoft.com/vcsharp/2005/overview/language/generics/>:
| The .NET Common Language Runtime creates a specialized copy of the
| native code for each generic type instantiation with a value type,
| but shares a single copy of the native code for all reference
| types (since, at the native code level, references are just
| pointers with the same representation).
Would someone mind putting that into different words?
There is a single copy of the IL for a generic type. However, when the JIT
compiler has to emit the native code for any particular spcialization of the
generic type there are issues. For reference types its easy, the native code
is just dereferencing a pointer to the type used to specialise the generic
so they can all share the same native code.
However for value types things are more complex. Variables of the
specializing type will be different sizes and so a generic instance will
occupy different amounts of space. What about floating point and integer
arithmatic, the machine instructions will be different for these. So for
value types the JIT compiler emits a different copy of the native code for
each specialization.
class Foo<T>
{
}
Foo<string> and Foo<SqlConnection> can share the same native code
Foo<int>, Foo<long> and Foo<float> each have their own copy
Regards
Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog http://www.dotnetconsult.co.uk