Skip to content

Make InlineStrings C-compatibleΒ #15

@KristofferC

Description

@KristofferC

Right now an InlineString is not C-compatible because there is no null trailing byte (in the case of all characters occupying the string) because the last byte stores the length of the string. There is a trick where, instead of storing the length of the string in the last byte, you store "the space left in the string", so if the max chars is 31 and you have 10 characters, you store 31 - 10 = 21 in the last byte. The point being that in the case of the string being full you would store a 0 there which would double-dip as the capacity left (which is zero) AND the trailing null byte making the string C-compatible.

This would allow wrapping an InlineString in a Ref, taking a pointer and passing it to a standard C-string function. And Julia will likely optimize away the Ref allocation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions