Skip to content

Make InlineStrings C-compatible #15

Closed

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.

Activity

  1. caseykneale commented on Mar 18, 2022

    @caseykneale
  2. bkamins commented on Mar 18, 2022

    @bkamins
  3. quinnj commented on Sep 4, 2026

    @quinnj
    Member

    Implemented in #94 for 2.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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