Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

CSimpleStringT::ReleaseBuffer

Releases control of the buffer allocated by GetBuffer.

void ReleaseBuffer( 
   int nNewLength = -1 
);
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.

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.

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

Header: atlsimpstr.h

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.