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 11:03

>>10
Yeah, I meant >>4.

The example code was posted because it only took 3 lines of meat to point out what kinds of problems >>1 would probably run into given such advice. And I've said 3 times now that this wasn't a submission but an example of a source of problems.  The comment about documenting it is important: you didn't say it yourself and it's a dirty solution.

This obsession you have with walking the list is particularly hilarious. If the advice in >>4 is to be useful it presumes the list will be walked at some point and the procedure can be folded in at that time.

If >>4 is how you recommend solving a problem you've got no grounds to criticize an implementation for being imperfect. Please do stick with C++ though. Linus and I will know to disregard your every opinion.

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