StrNew - C++ Builder

C++ Builder 参考手册 ➙ System::Sysutils ➙ StrNew


使用 StrAlloc 分配内存并且把字符串复制到这里

头文件:#include
命名空间:System::Sysutils
函数原型:

char *__fastcall StrNew(const char *Str);
System::WideChar *__fastcall StrNew(const System::WideChar *Str);

参数:

  • Str: 要复制的字符串

返回值:

  • 使用 StrAlloc 或 AnsiStrAlloc 分配一个 Delphi 兼容的字符串内存,然后把字符串 Str 复制到分配的内存,函数返回指向新分配内存里面字符串的指针;
  • 如果参数 Str 等于 nullptr,函数直接返回 nullptr;
  • 如果要释放这个函数分配的内存,需要使用 StrDispose 函数;
  • 可以通过函数 StrLen 获取字符串长度;
  • 可以通过函数 StrBufSize 获取内存里面可以存放的字节数,即分配内存时调用 StrAlloc 或 AnsiStrAlloc 的参数值;
  • 实际分配内存的字节数等于 Str 字符串长度 + 结束符 + 4个字节 占用的内存,有关分配内存的详细说明请参考 StrAlloc 和 AnsiStrAlloc。

例子:请参考 StrLen 和 StrBufSize 的例子。


相关:

  • System::Sysutils::StrAlloc
  • System::Sysutils::AnsiStrAlloc
  • System::Sysutils::WideStrAlloc
  • System::Sysutils::StrBufSize
  • System::Sysutils::StrLen
  • System::Sysutils::StrNew
  • System::Sysutils::StrDispose
  • System::Sysutils
  • System::UnicodeString
  • System::StringOfChar
  • System
  • std::malloc
  • std::calloc
  • std::realloc
  • std::free

C++ Builder 参考手册 ➙ System::Sysutils ➙ StrNew

你可能感兴趣的:(StrNew - C++ Builder)