They're counted, zero terminated, ASCII or Unicode, and magic as far as I'm concerned.
Oh... And a string copy is an O(1) operation as it only breaks the copy on modification.
Edit: correct to O(1), thanks mort96
They're counted, zero terminated, ASCII or Unicode, and magic as far as I'm concerned.
Oh... And a string copy is an O(1) operation as it only breaks the copy on modification.
Edit: correct to O(1), thanks mort96
But as with _all_ string solutions, it's the POSIX interface, standard library, and other libraries that screw you. If you're programming in C today, it's because you're integrating with a ton of C code, and thus it's impossible to make progress since the scope of improvement is so small.
It's always struck me as weird that Rust treats strings the way it does - the capacity value is not useful for many cases of strings, and it would have cost them one bit to special case the handling constant strings without the cap measure, which would be better. Most strings are _short_ which makes the overhead worse, proportionally.
Antirezs sds is just one example https://github.com/antirez/sds
The kind of person who calls a single pass through the string a "horribly inefficient solution" will faint at the idea of burdening every string with 16 more bytes of data.
I would additionally do the exact opposite: lock Python & Ruby developers in a room with only C for a few months.
C is a great language to learn programming, but Python or Ruby are, nowadays, in the most cases, better languages to program with. For example, C's sharpness is a notoriously famous source of bugs; yet it forces to develop rigor, discipline.
I'm not sure about that. There are plenty of 64-bit systems with less than 4GB of RAM
https://bstring.sourceforge.net/
The string keeps track of the buffer size and how much has been used, allowing allocations to be somewhat amortized. The string buffer itself is zero-terminated for easy interop with code that expects standard C strings.
struct tagbstring {
int mlen;
int slen;
unsigned char * data;
};
I used it on a microcontroller where I wanted something small and simple. The main missing feature is the lack of a small-string optimization like some implementations of std::string have. (Before anyone complains about this string type being too inefficient for a microcontroller, I had 1 MB of flash and 192KB of RAM, so I was not super constrained for resources)