StringReserve

메모리에 있는 문자열에 대해 지정된 크기의 버퍼를 예약합니다.

bool  StringReserve(
   string&    string_var,       // 문자열
   uint       new_capacity      // 문자열을 저장하기 위한 버퍼 크기
   );

Parameter

string_var

[in][out]  버퍼 크기를 변경해야 하는 문자열.

new_capacity

[in]  문자열에 필요한 버퍼 크기. new_capacity의 크기가 문자열 길이보다 작으면 현재 버퍼의 크기는 변경되지 않습니다.

반환값

실행이 성공하면 true를 반환하고, 그렇지 않으면 false를 반환합니다. 에러 코드를 받으려면, GetLastError() 함수를 호출해야 합니다.

참고

일반적으로 문자열 크기는 문자열을 저장하기 위한 버퍼 크기와 같지 않습니다. 문자열을 생성할 때 일반적으로 적절한 버퍼가 여백과 함께 할당됩니다. StringReserve() 함수를 사용하면 버퍼 크기를 관리할 수 있으며 이후 작업에 적합한 크기를 지정할 수 있습니다.

StringInit() 와는 달리, StringReserve() 함수는 문자열 내용을 변경하지 않고 문자로 채우지 않습니다.

예:

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");         
/* 결과:
    50msc 동안 통과된 StringReserve를 사용한 테스트
    121 msc 동안 통과된 StringReserve 없이 한 테스트
*/
  }

참고 항목

StringBufferLen, StringSetLength, StringInit, StringSetCharacter