Upcoming Events
Unite 2010
11/10 - 11/12 @ Montréal, Canada

GDC China
12/5 - 12/7 @ Shanghai, China

Asia Game Show 2010
12/24 - 12/27  

GDC 2011
2/28 - 3/4 @ San Francisco, CA

More events...
Quick Stats
63 people currently visiting GDNet.
2406 articles in the reference section.

Help us fight cancer!
Join SETI Team GDNet!
Link to us Events 4 Gamers
Intel sponsors gamedev.net search:

Contents
 Introduction
 Class Structure
 The Problem
 The Solution

 Printable version
 Discuss this article
 in the forums


The Problem

One problem was immediately apparent to me with this setup. I honestly had no idea who owned the pointers. For instance, take the Mesh class. I created it with a 'new' in my initialization procedure. Then I created a MeshObject, which is what controls where the Mesh is placed, how its animations are done, and so on. This way I only need one Mesh of a person to render an entire army, saving enormously on memory. The problem is, I passed the pointer to the Mesh into the constructor of the MeshObject, and so immediately there are two pointers to the Mesh; the application has one, and the MeshObject has one.

Now, in this case it is fairly obvious that the application should delete the Mesh and then the MeshObjects. But let's have a look at the SoundSystem class. I create a new Sound object and pass it into the SoundSystem class, where it is stored to be played later. Now the application has a pointer to the Sound, and so does the single SoundSystem class. Who deletes this one?

It became apparent to me that I was writing a game engine. The game code itself should never have to deal with any pointers to random engine elements, like vertex arrays or meshes or sounds.



Next : The Solution