u/tufflaxin r/C_Programming • Recommends
How to manage memory?
Hi!
I have mostly used garbage-collected languages so far. I'm learning C, and to me manual memory management looks hard.
The fundamental problem to me, it seems, is that sometimes it's not clear who (i.e. what part of the program, but I'm anthropomorphizing) is responsible for freeing the memory. Say you are writing a game, or something like that. And there are several subsystems in the game: a model with logic and data, a graphics subsystem, a sound subsystem, a persistent storage subsystem, etc. And imagine one subsystem allocates some memory, and hands it out to the other subsystems to do stuff with. Say the model allocates memory to hold a new character in the g…