Export (0) Print
Expand All

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.

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.

{
    // ...
    enum {
        bufferSize = 1024
    };
    CSimpleString s( "abc", pMgr );

    LPTSTR p = s.GetBuffer(bufferSize);
    strcpy_s( p, bufferSize , "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
}

Community Additions

ADD
Show:
© 2014 Microsoft