CSimpleStringT::FreeExtra

释放以前指定按字符串,但不再需要的任何额外的内存。

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

要求

Header: atlsimpstr.h

请参见

参考

CSimpleStringT选件类