A nonscientific look at the run-time memory profile of
ArrayList
and
List<T>
suggests that the dif-
ference in memory consumption is actually quite profound. I created a test that populated both data
containers with a collection of 200,000 integers. The
ArrayList
required 39MB to represent these values
whereas the
List<T>
instance appeared to only consume 16MB. That's a difference of 244 percent.
So, with all the attention focused on type safety and expressiveness, it may end up being the case that
performance actually represents the single most significant advantage offered by generics. Performance
gains of this magnitude are simply too compelling to ignore.
Backward Compatibility
It should be clear by now that a great deal of the elegance offered by the .NET generics implementation
was achieved through modifications to IL extensions. Of course, anytime you're talking about changing
IL, you're also talking about changing the CLR and -- more importantly -- you're talking about giving
up on any hope of backward compatibility. So, what does this mean in a practical sense? Well, if you're
building solutions that must run with prior versions of the CLR, you won't be able to take advantage of
generics. Any code you deploy with generics is going to require version 2.0 of the .NET Framework.
For most, this lack of backward compatibility will not be a significant issue. However, for some environ-
ments, it may pose a temporary migration problem. In the grand scheme, though, any hit that generics
may impose on backward compatibility is well worth some interim pain. The truth is, the generics exam-
ples you've seen in this chapter -- with all their optimizations and general efficiencies -- would not have
been achievable without introducing changes at the IL level.
Summar y
The goal of this chapter was to examine some of the more detailed facets of the .NET generics implemen-
tation. The chapter looked at many of the factors that played a role in shaping the overall vision for
introducing generics into the .NET platform. Beyond that, it also looked at how generics are represented
in IL and managed by the CLR at run-time. The chapter devoted a significant amount of time to dis-
cussing the generics code sharing scheme. It also looked at some basic performance metrics of generics
to provide a clearer view of the performance gains you can expect to achieve with generic types.
262
Chapter 11
14_559885 ch11.qxd 9/8/05 11:00 PM Page 262
Summary :
The truth is, the generics exam- ples you've seen in this chapter -- with all their optimizations and general efficiencies -- would not have been achievable without introducing changes at the IL level. The chapter looked at many of the factors that played a role in shaping the overall vision for introducing generics into the .NET platform. It also looked at some basic performance metrics of generics to provide a clearer view of the performance gains you can expect to achieve with generic types.
Tags :
chapter,compatibility,backward,performance,net,some,youre,looked,significant,any,talking,clr,adantage