Skip to content

Pre-initialised UTF string constants with memory.data<> #2972

Description

@geraintluff

Feature suggestion

I'd love a syntax like this:

let utf8Ptr = memory.data<u8>("Hello");
let utf16Ptr = memory.data<u16>("Hello");

At the moment I'm doing this at runtime instead:

let bytes = String.UTF8.byteLength(str, true);
let utf8Ptr = heap.alloc(bytes);
String.UTF8.encodeUnsafe(changetype<usize>(str), str.length, utf8Ptr, true);

I could use String.UTF8.encode() instead, and then store the ArrayBuffer so it doesn't get GC'd, but as far as I can tell, that still ends up embedding the UTF-16 string in the output.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions