CSimpleStringT::FreeExtra

更新 : 2007 年 11 月

文字列オブジェクトに割り当てられているメモリのうち、余分なメモリを解放します。

void FreeExtra( );

解説

このメソッドを使用すると、文字列オブジェクトによるメモリのオーバーヘッドを抑制できます。このメソッドは、GetLength の戻り値の正確な長さに合わせて、バッファを再割り当てします。

使用例

CAtlString basestr;
IAtlStringMgr* pMgr;

pMgr= basestr.GetManager();
ASSERT(pMgr != NULL);

// Create a CSimpleString with 28 characters
CSimpleString str(_T("Many sports are fun to play."), 28, pMgr);
_tprintf_s(_T("Alloc length is %d, String length is %d\n"),
   str.GetAllocLength(), str.GetLength());

// Assigning a smaller string won't cause CSimpleString to free its
// memory, because it assumes the string will grow again anyway.
str = _T("Soccer is best!");
_tprintf_s(_T("Alloc length is %d, String length is %d\n"),
   str.GetAllocLength(), str.GetLength());

// This call forces CSimpleString to release the extra
// memory it doesn't need.
str.FreeExtra();
_tprintf_s(_T("Alloc length is %d, String length is %d\n"),
   str.GetAllocLength(), str.GetLength());

解説

この例では、次のような出力が生成されます。

Alloc length is 1031, String length is 1024

Alloc length is 1031, String length is 15

Alloc length is 15, String length is 15

必要条件

ヘッダー : atlsimpstr.h

参照

参照

CSimpleStringT クラス

その他の技術情報

CSimpleStringT のメンバ