O'Reilly logo

Professional C# 2012 and .NET 4.5 by Morgan Skinner, Karli Watson, Jay Glynn, Bill Evjen, Christian Nagel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 14

Memory Management and Pointers

WHAT’S IN THIS CHAPTER?

  • Allocating space on the stack and heap at runtime
  • Garbage collection
  • Releasing unmanaged resources using destructors and the System.IDisposable interface
  • The syntax for using pointers in C#
  • Using pointers to implement high-performance stack-based arrays

WROX.COM CODE DOWNLOADS FOR THIS CHAPTER

The wrox.com code downloads for this chapter are found at http://www.wrox.com/remtitle.cgi?isbn=1118314425 on the Download Code tab. The code for this chapter is divided into the following major examples:

  • PointerPlayground
  • PointerPlayground2
  • QuickArray

MEMORY MANAGEMENT

This chapter presents various aspects of memory management and memory access. Although the runtime removes much of the responsibility for memory management from the programmer, it is useful to understand how memory management works, and important to know how to work with unmanaged resources efficiently.

A good understanding of memory management and knowledge of the pointer capabilities provided by C# will better enable you to integrate C# code with legacy code and perform efficient memory manipulation in performance-critical systems.

MEMORY MANAGEMENT UNDER THE HOOD

One of the advantages of C# programming is that the programmer does not need to worry about detailed memory management; the garbage collector deals with the problem of memory clean up on your behalf. As a result, you get something that approximates the efficiency of languages such as C++ without ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required