"CString" (编译类型)

"CString"

代表一个与 C 语言兼容的字符串.

更多信息

  • "CString" can be used in Typed and related constructs to specify a type.
  • Objects with type "CString" are not automatically memory managed and must be manually freed.
  • "CString""CArray"::["CChar"] 的一个.
  • "CString" 在 C 语言中等价于 char*unsigned char*.

函数构造

转换

    数组

  • 数组类型的范围包括从 Cast 到托管的 C 语言字符串. 支持的数组类型包括 "ListVector""NumericArray""PackedArray".
  • "String"

  • Cast 可用于将 "String" 对象转换为托管的 C 语言字符串.
  • "RawPointer" 和 "OpaqueRawPointer"

  • Cast 可用于 C 语言字符串和原始指针之间相互进行 bitcast 转换.

范例

打开所有单元关闭所有单元

基本范例  (1)

Compile a function that creates a managed C string and passes it to the C standard library function strlen to get its length:

在字符串上运算编译后的函数:

范围  (1)

Compile a function that parses a C string to a number using the atof library function from the C standard:

Evaluate the compiled function:

Convert a "CInt" to a string and store it in a managed C string of size 512:

可能存在的问题  (1)

"Managed" 对象之外创建的 C 语言字符串不会被自动管理内存,必须手动释放. 编译一个创建非托管 C 语言字符串的函数:

该函数泄漏内存:

使用 DeleteObject 来手动释放 C 语言字符串:

由此产生的函数不会泄漏内存: