StringReserve

Bellekteki bir dizge için belirtilen boyutta bir tampon ayırır.

bool  StringReserve(
   string&    string_var,       // dizge
   uint       new_capacity      // Bir dizge depolamak için tampon boyutu
   );

Parametreler

string_var

[in][out]  Tampon boyutunu değiştirmek istediğiniz dizge.

new_capacity

[in]  Bir dizge için gerekli tampon boyutu. Eğer new_capacity boyutu dizge uzunluğundan küçükse, geçerli tamponun boyutu değişmez.

Geri dönüş değeri

Eğer yürütme başarılı olursa true, aksi takdirde false olarak geri döner. Bir hata kodu almak için, GetLastError() fonksiyonu çağrılmalıdır.

Not

Genel olarak, dizge boyutu dizge depolamak için kullanılan tamponun boyutuna eşit değildir. Bir dizge oluştururken, uygun tampon genellikle bir kenar boşluğuyla ayrılır. StringReserve() fonksiyonu, tampon boyutunu yönetmeyi sağlar ve gelecekteki işlemler için en uygun boyutu belirtir.

StringInit() fonksiyonunun aksine, StringReserve() fonksiyonu dizge içeriğini değiştirmez ve bu içeriği karakterlerle doldurmaz.

Örnek:

void OnStart()
  {
   string s;
//--- StringReserve kullanmadan operasyon hızını kontrol et
   ulong t0=GetMicrosecondCount();
   for(int i=0; i< 1024; i++)
      s+=" "+(string)i;
   ulong msc_no_reserve=GetMicrosecondCount()-t0;
   s=NULL;
//--- şimdi, StringReserve kullanarak aynı şeyi yap
   StringReserve(s,1024 * 3);
   t0=GetMicrosecondCount();
   for(int i=0; i< 1024; i++)
      s+=" "+(string)i;
   ulong msc_reserve=GetMicrosecondCount()-t0;
//--- zamanı kontrol et
   Print("StringReserve ile test şu kadar sürdü: "+(string)msc_reserve+" msc");   
   Print("StringReserve olmadan test şu kadar sürdü: "+(string)msc_no_reserve+" msc");         
/* Sonuç:
    StringReserve ile test şu kadar sürdü: 50 msc
    StringReserve olmadan test şu kadar sürdü: 121 msc
*/
  }

Ayrıca bakınız

StringBufferLen, StringSetLength, StringInit, StringSetCharacter