StringReserve
保留内存中字符串的指定大小缓冲区。
bool StringReserve(
string& string_var,
uint new_capacity
);
|
参数
string_var
[in][out] 用于更改缓冲区大小的字符串。
new_capacity
[in] 字符串所需的缓冲区大小。如果new_capacity大小小于字符串长度,那么当前缓冲区大小不会更改。
返回值
注意
例如:
void OnStart()
{
string s;
//--- 不使用StringReserve检查操作速度
ulong t0=GetMicrosecondCount();
for(int i=0; i< 1024; i++)
s+=" "+(string)i;
ulong msc_no_reserve=GetMicrosecondCount()-t0;
s=NULL;
//--- 现在,让我们使用StringReserve执行相同操作
StringReserve(s,1024 * 3);
t0=GetMicrosecondCount();
for(int i=0; i< 1024; i++)
s+=" "+(string)i;
ulong msc_reserve=GetMicrosecondCount()-t0;
//--- 检查时间
Print("Test with StringReserve passed for "+(string)msc_reserve+" msc");
Print("Test without StringReserve passed for "+(string)msc_no_reserve+" msc");
/* Result:
Test with StringReserve passed for 50 msc
Test without StringReserve passed for 121 msc
*/
}
|
另见
StringBufferLen,StringSetLength, StringInit,StringSetCharacter