When the memory is not owned by the C code, -- i.e. when creating or initializing a struct in OCaml before passing it to C -- then the string view isn't a good choice, because there's no way to manage the lifetime of the C copy of the generated OCaml string.
Meanwhile, the tutorial from the "Real World OCaml" defines two functions addstr and mvwaddstr, which both take a string owned by OCaml:
let addstr = foreign "addstr" (string @-> returning void)
let mvwaddstr =
foreign
"mvwaddstr"
(window @-> int @-> int @-> string @-> returning void)
From the documentation:
Meanwhile, the tutorial from the "Real World OCaml" defines two functions
addstr
andmvwaddstr
, which both take a string owned by OCaml: