Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C memory management

Name: Anonymous 2011-02-12 5:42

Hey /prog, I'm teaching myself C by writing a roguelike and I noticed that C uses manual memory management for creating objects in the heap. I was wondering if the C-gods could lend me some advice on how to proceed with this:

I want to write a roguelike with thousands of NPCs, every NPC is a really small piece of data which does not contain any pointers (position, stats, behavior... probably ends up being a few bytes). NPCs would spawn and die constantly. How would I go about managing the memory for this?

• malloc and free individual NPCs
• Boehm-Demers-Weiser conservative garbage collector
• malloc a big chunk of memory and build some kind of memory manager on top of it (are there techniques for this?)

Please advice.

Name: Anonymous 2011-02-12 10:21

>>8
Uh yeah. You might want to focus on reading comprehension before you give people programming advice. Here's what you didn't get from my post:

a) make sure you document it if you write code like this.
b) an alternative is better.
c) yet another alternative is better.


Obviously you didn't read much of the post, particularly the part immediately before the code and the part about the additional struct member.
Obviously this is in the context of >>7 and should be treated as such.
Obviously >>7 is not the way to do it if you're interested keeping around extra information around.

Anyway since I'm repeating myself: this was an example of what code might look like according to >>7's corner-cutting suggestion, nothing like code I'd ever write. I'm not sure where you got that idea, since I declaimed the design at least twice.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List