The One with the Memory Games
Efficient Memory Management
Performance is critical for system programming. We discussed this in the previous chapter and outlined why it is crucial. Memory consumption is just as important, however. The trouble is that better performance often leads to worse memory usage. And trying to optimize for memory usage often leads to worse performance. As in all things in life, it is a matter of compromising.
That being said, you might also encounter situations where you get both simultaneously – for instance, using the stack instead of the heap (or value types instead of reference types) results in faster code using less memory.
However, you usually don’t get one item for free while pursuing the other. You have to make informed decisions and the correct choices. And that is what this chapter is all about. I hope you remember most of it once we reach the end of this chapter!
In this chapter, we’ll cover the following topics:
...