Small Buffer Optimization for string and friends

Andrej Mitrovic andrej.mitrovich at gmail.com
Mon Apr 9 08:37:27 PDT 2012


On 4/9/12, Jakob Ovrum <jakobovrum at gmail.com> wrote:
> It's also common to avoid the `toStringz` function for strings
> you know are zero-terminated, using `.ptr` directly instead.

Yup. E.g. WinAPI text drawing functions take a wchar* and a length. I
don't have to call toUTF16z but just pass a pointer, or even a pointer
to a specific element via &arr[index] (after calling std.utf.stride,
of course).

> the toStringz function unconditionally appends a zero these days

The one taking (const(char)[] s) does this, but not the other overload
taking (string s). Whether or not that's safe I don't really know.
I've had an argument over this on github, but I don't know if it was
about toStringz or maybe toUTF16z. I haven't got the link to the
discussion.


More information about the Digitalmars-d mailing list