4 ms·
My version of this (from 1992!) is here: https://sourceforge.net/p/joe-editor/mercurial/ci/default/tree/joe/vs.h https://sourceforge.net/p/joe-editor/mercurial
by jhallenworld 7y ago
My version of this (from 1992!) is here:
https://sourceforge.net/p/joe-editor/mercurial/ci/default/tree/joe/vs.h https://sourceforge.net/p/joe-editor/mercurial/ci/default/tr...
I also have NULL terminated arrays of strings, like arguments lists:
https://sourceforge.net/p/joe-editor/mercurial/ci/default/tree/joe/va.h https://sourceforge.net/p/joe-editor/mercurial/ci/default/tr...
It's set up so that you could make a dynamic arrays of any types by copying the header and source files, but changing a few constants and providing comparison and duplication functions for the elements involved. It's like manual template instantiation.
Of course this is prone to memory leaks, same as sds. But there is branch here:
https://sourceforge.net/p/joe-editor/mercurial/ci/coroutine/tree/joe/obj.h https://sourceforge.net/p/joe-editor/mercurial/ci/coroutine/...
In this version, all strings are allocated on an obstack. Space for temporary strings is automatically reclaimed when you return to the top level.
You can mark a string as permanent, then it will not be reclaimed, and instead has to be explicitly freed. So you can still have memory leaks but less likely, and also you could have accidental automatic freeing, but a lot of explicit frees are eliminated.
C++ strings are better... except that I have my own library for them also because I hate not being able to return NULL to indicate a failure. This is called the semi-predicate capability of C strings, and is easy to have in C++ with a different library.