CString::ReleaseBuffer

Syntax

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 CString size to the current length of the string.

Remarks

Use ReleaseBuffer to end use of a buffer allocated by GetBuffer.

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, then use nNewLength to specify its length.

The address returned by GetBuffer is invalid after the call to ReleaseBuffer or any other CString operation.

Example

CString s;

char* p = s.GetBuffer( 1024 );

s = "abc";

ASSERT( s.GetLength() == 3 ); // String length = 3

s.ReleaseBuffer(); // Surplus memory released, p is now invalid

ASSERT( s.GetLength() == 3 ); // Length still 3

See Also

CString::GetBuffer