有 malloc的地方 就有指针,
举个简单的例子,假如现在 游戏进入一个场景,
init initFight(void)
{
readMap();
readPlayers();
readEnemies();
readNpc();
readEffects();
readUiData();
...
}
退出一个场景
void exitFight(void)
{
freeMap();
freePlayers();
freeEnemies();
freeNpc();
freeEffects();
freeUiData();
...
}
void readPlayers(void)
{
int i;
for (i = 0; i < PLAYER_NUM; i++)
{
readPlayer(i);
}
}
void readPlayer(int playerId)
{
players[playerId]->modules = readActorModules();
players[playerId]->frames = readActorFrames();
players[playerId]->actions = readActorFrames();
...
}
void freePlayers(void)
{
int i;
for (i = 0; i < PLAYER_NUM; i++)
{
freePlayer(i);
}
}
void freePlayer(int playerId)
{
freeActorModules(players[playerId]->modules);
...
}