3.4 String Types
3.4.1 Primitive String Types
See also _bytes/nul-terminated and _bytes for converting between byte strings and C’s char* type.
value
For the 3m and CGC variants of Racket, the conversion of a Racket string for the foreign side shares memory with the Racket string representation, since UCS-4 is the native representation format for those variants. The foreign pointer corresponds to the mzchar* type in Racket’s C API.
For the CS variant of Racket, the conversion of a Racket string for the foreign side is a copy of the Racket representation, where the copy is managed by the garbage collector.
value
The conversion of a Racket string for the foreign side is a copy of the Racket representation (reencoded), where the copy is managed by the garbage collector.
For the 3m and CGC variants of Racket, the conversion of a Racket path for the foreign side shares memory with the Racket path representation. Otherwise (for the CS variant or for Racket strings), conversion for the foreign side creates a copy that is managed by the garbage collector.
Beware that changing the current directory via current-directory does not change the OS-level current directory as seen by foreign library functions. Paths normally should be converted to absolute form using path->complete-path (which uses the current-directory parameter) before passing them to a foreign function.
For the 3m and CGC variants of Racket, the conversion of a
Racket symbol for the foreign side shares memory with the Racket
symbol representation, but points to the middle of the symbol’s
allocated memory—
For the CS variant of Racket, the conversion of a Racket symbol for the foreign side is a copy of the Racket representation, where the copy is managed by the garbage collector.
3.4.2 Fixed Auto-Converting String Types
3.4.3 Variable Auto-Converting String Type
The _string/ucs-4 type is rarely useful when interacting with foreign code, while using _bytes/nul-terminated is somewhat unnatural, since it forces Racket programmers to use byte strings. Using _string/utf-8, etc., meanwhile, may prematurely commit to a particular encoding of strings as bytes. The _string type supports conversion between Racket strings and char* strings using a parameter-determined conversion.
parameter
(default-_string-type type) → void? type : ctype?
3.4.4 Other String Types
value
value