1.) Has anybody implemented gc_alloc in a DikuMud and/or have advice or guidance on it? 2.) Is the effort as simple as replacing the malloc/calloc calls with gc_malloc? 3.) Can you still free your memory or do you simply let it go and let the garbage collector do it (e.g. are things like free_string then removed?)?
I've run Valgrind against my code and only found one leak, but I'd trade resources for safety and ease of use.
I've scouted github for examples in a Diku code base but haven't found any (I'm running a modified ROM 2.4 myself).
Any guidance or advice or examples would be appreciated.
Basically, when using gc_malloc, that memory allocator takes over calls to malloc/calloc/alloca, and calls to free effectively become no-ops. The garbage collection itself needs to be called periodically, and can be somewhat costly, so you'll want to put it in your main loop and interleave it with your other periodic calls so you don't try to garbage collect on the same tick you're also updating all the weather systems, or whatever else might be expensive in your game.
That makes sense. To check my assumption, I would no longer need to free_string something when setting it because the old reference would be collected when I call collect (this is assuming I keep the str_dup construct and swap the calls in the plumbing)?