I'm wondering if there is a good and portable way to automatically resize buffers in C, particularly when using vsprintf.
I'm considering asprintf and vasprintf, but I'd rather use alloca than malloc so I don't have to free() stuff myself, unless someone knows of an easy way to automatically free memory the moment it gets out of scope.
I guess it's also an option to make the code c++ compatible and using c++'s string library? I've never gone that route before so I'm not sure how much work that'd entail.
15 Jul, 2009, David Haley wrote in the 2nd comment:
Votes: 0
Using C++ is a piece of cake. Far easier solution unless you really have to stay in C only.
Given it's for TinTin++ portability is an issue, but I assume g++ is as widely available as gcc. Any suggestions for a good online c++ manual that has a section on strings?
15 Jul, 2009, David Haley wrote in the 7th comment:
Votes: 0
Depending on what you're actually doing with this, you might want to also look into streams, like string-backed streams (osstream or ostrstream, IIRC, depending on which version of the STL you're using).
I'm considering asprintf and vasprintf, but I'd rather use alloca than malloc so I don't have to free() stuff myself, unless someone knows of an easy way to automatically free memory the moment it gets out of scope.
I guess it's also an option to make the code c++ compatible and using c++'s string library? I've never gone that route before so I'm not sure how much work that'd entail.