Next: , Previous: , Up: Strings   [Contents][Index]


foreign-string-alloc

foreign-string-alloc

Syntax

Function: foreign-string-alloc string &key encoding null-terminated-p start end ⇒ pointer

Arguments and Values

string

A Lisp string.

encoding

Foreign encoding. Defaults to *default-foreign-encoding*.

null-terminated-p

Boolean, defaults to true.

start, end

Bounding index designators of string. 0 and nil, by default.

pointer

A pointer to the newly allocated foreign string.

Description

The foreign-string-alloc function allocates foreign memory holding a copy of string converted using the specified encoding. Start specifies an offset into string and end marks the position following the last element of the foreign string.

This string must be freed with foreign-string-free.

If null-terminated-p is false, the string will not be null-terminated.

Examples

  CFFI> (defparameter *str* (foreign-string-alloc "Hello, foreign world!"))
  ⇒ #<FOREIGN-ADDRESS #x00400560>
  CFFI> (foreign-funcall "strlen" :pointer *str* :int)
  ⇒ 21

See Also

foreign-string-free
with-foreign-string