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 CS implementation 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.
For the BC implementation 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.
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 BC implementation of Racket, the conversion of a Racket path for the foreign side shares memory with the Racket path representation. Otherwise (for the CS implementation 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 CS implementation 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.
For the BC implementation 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—
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.
Don’t use _string when you should use _path. Although C APIs typically represent paths as strings, and although the default _string (via default-_string-type) even implicitly converts Racket paths to strings, using _path ensures the proper encoding of strings as paths, which is not always UTF-8. See also _path for a caveat about relative paths.
parameter
(default-_string-type type) → void? type : ctype?
3.4.4 Other String Types
value
value