Le quartidi 14 frimaire, an CCXXIV, Ganesh Ajjanagadde a écrit : > > And while we are at it, we should change them to accept strings as > > pointer+length or pointer+end instead of zero-terminated C strings. > Are you referring here to something like djb's netstrings: > http://cr.yp.to/proto/netstrings.txt?
Not exactly. What you quote is for external representation: serializing to files or sockets. It would be really inefficient for using inside programs due to the endless ASCII-decimal conversion. . What I am saying is that strings should be something like this: struct string { char *text; size_t len; }; or possibly: struct string { char *text; char *end; }; ... not just "char *text" and a 0 byte at the end. There are many reasons for this, the most obvious is this: if you want to extract a substring in the middle (or the beginning, but not the end), with the 0-termination convention, you have to change the original string to place the 0, or to copy it if you can not modify it. With the structure, you just have to adjust the len/end field. Most languages except C work with strings like that; 0-termination is really an oddity of the C language (and, unfortunately the kernels that are build around it). (As for the choice between len and end, it depends on the use case; len is probably better for general-purpose code, but when walking the string, end is constant. Fortunately, they are an addition/subtraction away from each other.) (Also, char* would rather be uint8_t*, to handle UTF-8.) Regards, -- Nicolas George
signature.asc
Description: Digital signature
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel