Hacker News new | ask | show | jobs
by accelbred 60 days ago
Many of the big C++ projects I've worked with have custom string types since the standard one was defficient for some reason or another.
2 comments

Exactly, and a simple usable string type is just a struct MyString { char *buf; size_t len; }; away. Actual magic is in how you use it, where you allocate it, how you integrate allocation and formatting and logging and I/O... i.e. all the things that aren't solved by crufty complex std::string either.
So simple, and yet most C projects never do it.

Plain C strings all over the place.

Since I learnt C in 1990, knowing to count up to 10 is enough, for the amount of times I saw it actually being done.

The projects and people I follow do this all the time. Just like putting a size field near each regular non sentinel terminated array is useful. But if not doing it (maybe linux kernel in many cases), no big deal either, don't sweat the small stuff. String slices are small and rarely perf critical.
And yet zillion ways better than C strings, which was the point.