BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Changes and Improvements to the Base Class Library

Changes and Improvements to the Base Class Library

This item in japanese

Since 2005, the base class library was in stasis. While the rest of the .NET framework evolved and built upon the 2.0 version of the CLR, the base class library team has been slowly building their wish list. With .NET 4, a new version of the CLR and BCL is on deck and these enhancements can finally be realized.

New Types

Languages like IronPython and F# have something simple and yet entirely alien to the core .NET languages, a real integer type. Unlike VB and C#, which limit integers to what fits in a given set up bits, these languages can hold virtually any value. But in order to share values between the two, to say nothing of other languages, a common implementation is needed. The base class library will be adding BigInteger. This high performance implementation was jointed developed by the BCL team and the Microsoft Solver Foundation.

Another typed added primarily for F# and IronPython is Tuples. Tuples themselves are fairly trivial, essentially just being a data structure that holds a fixed-length set of values. In some ways it is like an array, but each value can have a different type. Like BigInteger, the primary reason for including it at the BCL level is to avoid duplicate, incompatible implementations.

Under collections is the SortedSet class. This is yet another class that supports sorted collection of objects where each sort key must be unique. Still missing is a sorted list that allows duplicates.

Unmanaged Memory Support

When working with very large files, native developers turn to a technique known as Memory-Mapped Files. As the name implies, a memory-mapped file maps a file-like construct to an address in memory. In addition to actual files, devices and shared memory objects can be mapped. One of the most common uses of a memory-mapped file is inter-process communication. To do this, each application opens the same file descriptor. With the next version of the BCL, .NET developers will be able to use memory-mapped files directly instead of via platform invoke calls.

Internationalization

The Resource Manager for both .NET 4 and Silverlight 2 will support the user's preferences for UI languages instead of just default the to the CurrentUICulture's chain. This is especially important when a user has more than one preferred language.

Breaking Changes

The default comparison logic for several System.String methods have been changed. This should not affect English-only applications, but it may have an impact on internationalized applications.

The default partial matching overloads on System.String (StartsWith, EndsWith, IndexOf, and LastIndexOf) have been changed to be culture-agnostic (ordinal) by default. In addition, ToUpper and ToLower on System.String and System.Char have been changed to use the invariant culture instead of the current culture. Although we have guidance and FxCop rules that recommend always using overloads that take a StringComparison parameter, unaware developers often just use the default overloads. In previous versions of .NET, these default overloads do a culture-sensitive comparison using the current culture. This can often lead to subtle bugs, most notably security vulnerabilities, when unaware developers use the default overloads to do security-sensitive string comparisons.

Performance Improvements

Currently the methods on Directory and DirectoryInfo return arrays. This means that the entire array of files has to be populated before a single entry is accessed. With the addition of IEnumerable support for Directory and DirectoryInfo, the first file in the directory can be accessed immediately while the rest of the list is lazily populated.

Rate this Article

Adoption
Style

BT