Long time viewer, first time poster here.
Somehow it's been about 300 episodes and all this time Casey has managed to eschew heavy usage of c-style strings. In the few places where he uses them (asset builder, debug system and platform layer), he simply makes due with declaring a char Buffer[N] on the stack and going along his way.
I'm working on a large-ish project at the moment and using the coding philosophy and techniques from HH has gotten me tremendously far. However, I've finally hit a wall and I'm curious about other people's opinions on the matter. The game I am working on will have a lot of strings. It's not a text game, but it is text-heavy: plenty of offline stuff e.g. descriptions, and plenty of online stuff e.g. a log of events that occur in the game. So far, I have been recklessly slinging char Buffer[N] left and right, using filth like strcpy, strlen, and worst of all sprintf, continuously telling myself that I will soon figure something out and get this mess under control. I don't think I've had an overflow bug yet, but at this rate it's only a matter of time.
As of now, I can only see these options:
1) Keep doing what I'm doing, except upgrade all the string.h calls with their max-byte counterparts.
Pros - Least friction.
Cons - Need to keep track of size when appending to a buffer. Of course, the fact I haven't had catastrophic memory corruption bugs means I'm already doing this implicitly to some extent.
- Still uses string.h. Not the end of the world, but still lame.
2) Make a struct string that holds the length and capacity and allocates a fixed-size array from the Transient State's memory.
Pros - Size is already saved for automatic use when appending to a buffer.
Cons - Need to pass the Transient State to every function that makes a string (many).
- Need to wrap every new string and its usage with BeginTemporaryMemory and EndTemporaryMemory calls.
3) Same as 2), but make a separate arena for "scratch-space" that gets its size set to 0 at the beginning of each frame.
Pros - Don't have to call Begin and EndTemporaryMemory everywhere.
Cons - Still need to pass this scratch arena to all the functions that make strings.
4) Give up and use malloc(). Or even worse, give up and use a string library... Just kidding.
I am leaning toward the third option but I'm curious about other people's thoughts.
So, how do you deal with strings when you have to use them frequently?