Developer .NET UPDATE—brought to you by the Windows & .NET Magazine Network
THIS ISSUE SPONSORED BY
Microsoft ASP.NET Connections, VB Connections, and Win-Dev
Windows & .NET Magazine LIVE!
SQL Server Magazine LIVE!
(below DEVELOPER .NET PERSPECTIVES)
SPONSOR: MICROSOFT ASP.NET CONNECTIONS, VB CONNECTIONS, AND WIN-DEV
LAST CHANCE TO ATTEND THIS YEAR'S LARGEST INDEPENDENT .NET DEVELOPER EVENT
Microsoft ASP.NET Connections, VB Connections, and Win-Dev 2002 are co-locating their events to deliver the largest independent .NET developer-focused event on April 29-May 4, 2002, in New Orleans. That's three events—more than 140 sessions—for one low price! Learn from real-world pros in sessions about Web development, XML and data management, .NET framework internals, Web forms, .NET basics, .NET Web security, CLR classes, VB 6.0, VB.NET, VC++, C#, ASP.NET, application debugging, and more. Come early and enjoy a full day of VS.NET training with the Microsoft product team. Register now!
April 23, 2002—In this issue:
1. DEVELOPER .NET PERSPECTIVES
- Stringing Your Page Along
- Cast Your Vote for our Reader's Choice Awards!
- Get One Step Closer to Certification at CertTutor.net
- Featured Thread: Visual Studio .NET Project Creates an Unwanted Active Connection
4. NEW AND IMPROVED
- Recompile Your COBOL-85 Programs
5. CONTACT US
- See this section for a list of ways to contact us.
1. DEVELOPER .NET PERSPECTIVES
(contributed by Bill Sheldon, [email protected])
A common way to build a Web page full of dynamic content is to concatenate the various strings that compose the page. A fellow developer told me that the concatenation of strings when returning a dynamic page was inevitable. Yet string manipulation can be one of the slowest and most memory-intensive actions your page can perform. So, let's have a quick look at what string manipulation is about, why concatenation can be such a performance dog, and how a new class in the Microsoft .NET Framework can help you avoid this performance pitfall.
As most developers know, everything boils down to bits and bytes. A string is, by definition, a contiguous set of bytes, each of which contains the numeric representation of a character. (In the case of Unicode, two bytes contain the numeric representation of a character.) In some low-level languages such as C++, you can manipulate memory at the address level to achieve fast string manipulation. However, even in languages such as C++, such manipulation is limited and tricky.
Consider what happens when you use a string-related class such as the C++ language's CString class or the .NET Framework's String class (which is part of the System namespace) to manipulate a string. The class references an underlying array of bytes containing the characters. You might think that when you concatenate additional characters to a string, the class simply extends the size of its array of bytes and copies the additional characters to those bytes. Unfortunately, the real process is more involved. The class determines how many bytes it needs to store the entire string and requests that array of bytes from the available free memory. The class then copies the characters from the original set of bytes and the additional characters into this new memory location. Finally, the class releases the memory associated with the original string.
The key here is that each time you manipulate a string, the string-related class must create a new copy of that string in memory. For relatively small strings, this process isn't a big deal, but for a full page of dynamic content, it can easily consume tens of thousands or even hundreds of thousands of bytes. Although you intend to append only another 20 characters to the end of your page, the system must create a second in-memory copy of your entire page. This situation worsens because the system is looking for a set of contiguous bytes to hold those characters.
As you can imagine, this problem isn't new. The Microsoft article "HOWTO: Improve String Concatenation Performance" provides a trick to work around the problem. Unfortunately, as the article notes, the code that the article provides is for use at your own risk.
Microsoft provides a true solution to the string manipulation challenge in the .NET Framework. The base string class in the .NET Framework isn't the String class that I mentioned earlier but rather the StringBuilder class, which is part of the System.Text namespace. The StringBuilder class provides what Microsoft describes as a "mutable" string. This class has some of the same functions as a traditional string class, but the StringBuilder class doesn't store your characters as a contiguous set of bytes. I won't go into the details of the process, but essentially here's the scoop: When you want to add another 20 characters to the end of your page, instead of referencing all the current characters, this class simply allocates another 20 individual memory locations and associates them with the last character in your current string. The same process occurs when you remove or otherwise manipulate characters in a large string.
By manipulating only the storage associated with the characters you're editing, the StringBuilder class provides much faster performance than the String class. However, this performance improvement comes at a price: Creating this class takes longer than creating a traditional string class. So, the StringBuilder class isn't something you want to use for every string. Instead, you need to consider the amount of manipulation you need to put a string through. For a large string that will see significant manipulation, the improvement in performance will make using the StringBuilder class worth your while.
The StringBuilder class isn't the best performance enhancement in the .NET Framework. I'm building up to the more radical elements. Next week, I'll tell you about one of the truly major performance-enhancing elements in the .NET Framework: server-side caching.
SPONSOR: WINDOWS & .NET MAGAZINE LIVE! AND SQL SERVER MAGAZINE LIVE!
WINDOWS & .NET MAGAZINE LIVE! TO CO-LOCATE WITH SQL SERVER MAGAZINE LIVE!
WINDOWS & .NET MAGAZINE LIVE! and SQL SERVER MAGAZINE are co-locating their events at one conference on May 5-9, 2002, in Palm Springs, CA. That's two events—more than 100 sessions—for one low price! This conference is guaranteed to bring you the ROI you need to justify a few days out of the office (especially in today's economy). After just a couple of sessions, you'll be itching to implement the time- and resource-saving tips you've learned. Register today before this event sells out!
Which companies and products do you think are the best on the market? Nominate your favorites in four different categories for our annual Windows & .NET Magazine Reader's Choice Awards. You could win a T-shirt or a free Windows & .NET Magazine Super CD, just for submitting your ballot. Click here!
Announcing the CertTutor.net Web site! Here you can find practice exams, discussion forums, articles, and much more—all designed to help you reach your goal of Microsoft or Cisco Certified Network Associate (CCNA) certification. Check it out!
Bob is starting to explore Visual Studio .NET and has created a "Hello World" page that runs OK on his current system. However, when he builds and runs the project in Visual Studio .NET, the project creates an unwanted active connection in Microsoft IIS. If you can help Bob solve this problem, join the discussion at the following URL:
4. NEW AND IMPROVED
Fujitsu released NetCOBOL for .NET, a development environment for COBOL built for Visual Studio .NET. The environment lets companies that have existing COBOL assets recompile and enhance their COBOL-85 programs. NetCOBOL for .NET uses the Microsoft .NET Framework's ability to develop XML Web services so that COBOL programmers can expose their code as components. For pricing, contact Fujitsu at 408-432-1300.
5. CONTACT US
Here's how to reach us with your comments and questions:
- ABOUT DEVELOPER .NET PERSPECTIVES — [email protected]
- ABOUT THE NEWSLETTER IN GENERAL — [email protected] (please mention the newsletter name in the subject line)
- TECHNICAL QUESTIONS — http://www.winnetmag.net/forums
- PRODUCT NEWS — [email protected]
- QUESTIONS ABOUT YOUR DEVELOPER .NET UPDATE SUBSCRIPTION? Email Customer Support — [email protected]
- WANT TO SPONSOR DEVELOPER .NET UPDATE?
This weekly email newsletter is brought to you by Windows & .NET Magazine, the leading publication for Windows professionals who want to learn more and perform better. Subscribe today.
Receive the latest information about the Windows and .NET topics of your choice. Subscribe to our other FREE email newsletters.