Game Development Reference
In-Depth Information
Chapter 22
Managing Memory for Game
Developers
This chapter is the first in the last part of this topic, which will cover general game development
topics that are important for new programmers to attempt to grasp. The first of these chapters is
going to introduce you to the C++ memory model and the implications of using different types
of memory.
Memory management is a very important topic in game development. All games go through a period
in development where memory is running low and the art team would like some more for extra
textures or meshes. The way memory is laid out is also vitally important to the performance of your
game. Understanding when to use stack memory, when to use heap memory, and the performance
implications of each are important factors in to being able to optimize your programs for cache
coherency and data locality. Before you can understand how to approach those problems you will
need to understand the different places where C++ programs can store their data.
There are three places in C++ where you can store your memory: There is a static space for storing
static variables, the stack for storing local variables and function parameters, and the heap (or free
store) from where you can dynamically allocate memory for different purposes.
Static Memory
Static memory is handled by the compiler and there isn't much to say about it. When you build your
program using the compiler, it sets aside a chunk of memory large enough to store all of the static
and global variables defined in your program. This includes strings that are in your source code,
which are included in an area of static memory known as a string table.
There's not much else to say regarding static memory, so we'll move on to discussing the stack.
225
 
Search WWH ::




Custom Search