Re:Sentinels Can Be Faster
by colejohnson66 on Wednesday September 09, 2020 @06:12PM
(#24426520)
Weren’t “Pascal strings” limited in that they were only a byte though? So, your string could only be 255 bytes long (conveniently going to a nice round 256 when you add the length byte).
Re:Sentinels Can Be Faster
by steveklabnik on Wednesday September 09, 2020 @06:15PM
(#24426538)
Yep!
And yeah, in Rust we have a separate CString type that's null terminated, so you may need a copy to move between the two worlds. It just depends, if you're only reading, for example, then you can create a pointer + len where the length doesn't include the 0, and that's effectively zero cost.
You got me curious about my days as a kid putting "pascal" in front of Mac System 7 stuff; I believe that it only accepted Pascal strings. I also vaguely remember people doing funny stuff like null terminating pascal strings anyway and then putting the length before the actual pointer so that you get both in one...