CString::ReleaseBuffer
This method releases a buffer allocated by GetBuffer. If you know that the string in the buffer is null-terminated, you can omit the nNewLength parameter. 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 CString operation.
void ReleaseBuffer(
int nNewLength = –1 );
Parameters
- nNewLength
Specifies 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 CString size to the current length of the string.
Example
The following example demonstrates the use of CString::ReleaseBuffer.
// example for CString::ReleaseBuffer CString s; s = "abc"; LPTSTR p = s.GetBuffer( 1024 ); strcpy(p, "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
Windows CE versions: 1.0 and later
Header file: Declared in Afx.h
Platform: H/PC Pro, Palm-size PC, Pocket PC