CSimpleStringT::ReleaseBuffer
Releases control of the buffer allocated by GetBuffer.
void ReleaseBuffer(
int nNewLength = -1
);
Parameters
- nNewLength
The new length of the string in characters, not counting a null terminator. If the string is null terminated, the -1 default value sets the CSimpleStringT size to the current length of the string.
Remarks
Call this method to reallocate or free up the buffer of the string object. If you know that the string in the buffer is null terminated, you can omit the nNewLength argument. If your string is not null terminated, use nNewLength to specify its length. The address returned by GetBuffer is invalid after the call to ReleaseBuffer or any other CSimpleStringT operation.
Example
The following example demonstrates the use of CSimpleStringT::ReleaseBuffer.
const int bufferSize = 1024;
CSimpleString s(_T("abc"), pMgr);
LPTSTR p = s.GetBuffer(bufferSize);
_tcscpy_s(p, bufferSize , _T("abc")); // use the buffer directly
ASSERT(s.GetLength() == 3); // String length = 3
s.ReleaseBuffer(); // Surplus memory released, p is now invalid.
ASSERT(s.GetLength() == 3); // Length still 3
Requirements
Header: atlsimpstr.h