Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.


Releases control of the buffer allocated by GetBuffer.

void ReleaseBuffer(
   int nNewLength = -1



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

© 2015 Microsoft