How do generics get compiled by the JIT compiler?

后端 未结 2 1527
失恋的感觉
失恋的感觉 2020-12-05 07:05

I know that generics are compiled by JIT (like everything else), in contrast to templates that are generated when you compile the code.
The thing is that new generic typ

2条回答
  •  一整个雨季
    2020-12-05 07:40

    Reference types generics all become the same type; value type generics are instantiated separately.

    This is because reference types are all really just Object references (4 or 8 bytes), whereas value types are different and cannot be handled by a single piece of code, due to stack layout differences, etc. Therefore, instantiating multiple copies of a generic type with value types will increase the memory usage by a lot, whereas instantiating multiple copies with reference types won't.

提交回复
热议问题