Skip to content
FutureBlitz

    Install

    Import std.ffi.cstring

    std.ffi.cstring

    CStrings that C code can keep: copies of Strings, their lengths, and freeing them.

    What a CString does besides ToString, which is built in: a copy of a String that C code can keep, its length, and giving the copy back. The copy is the runtime's, like the one an Extern Function's call makes of a String argument, so leak reports count one that's never freed.

    std/ffi/cstring.fb

    Extends

    CString extend

    Extend CString

    What a CString does besides ToString: a copy of a String that C code can keep, its length, and giving the copy back.

    std/ffi/cstring.fb, line 15

    • Public Static Method From(text: String): CString static method #

      A CString of text's UTF-8 bytes and a NUL, in memory of its own, which C code can keep until Free gives it back. C reads it up to its first NUL, so a NUL in text ends it there.

      Examples

      Local copy = CString.From("hello")
      Unsafe
          Expect(copy.Length() == 5)
          copy.Free()
      End Unsafe
    • @PanicsAtCaller Public Unsafe Method Length(): Int64 method #

      How many bytes it has before its first NUL. Panics when it's Null.

    • @PanicsAtCaller Public Unsafe Method Free() method #

      Gives back what From made, and nothing else, which panics. Null is nothing to give back.

    Report an issue with this page or with FutureBlitz on GitHub.