
August 21st, 2008, 04:16 AM
|
|
Contributing User
|
|
Join Date: May 2006
Posts: 763
Time spent in forums: 2 Days 3 h 52 m
Reputation Power: 4
|
|
|
Member variable of STL string class
Hello everyone,
Today I have some free time to debug into string class itself. Here is the related sample code I debugged.
Two questions,
1. I have debugged that for small buffer (size <= 15), string will use buffer on stack, char array, and for larger buffer (>15), the space on heap is used (and destructor of string will free the space on heap), correct?
2. What is the function of the internal member variable _Bx._Buf and _Bx._Ptr? I have posted my debug results and why sometimes _Bx._Ptr is bad ptr and sometimes _Bx._Ptr has valid content.
I debugged under VS 2008.
Code:
#include <string>
using namespace std;
string foo()
{
string b;
b.append ("msdn");
// at this point _Bx._Buf content is msdn, _Bx._Ptr is bad ptr
b.append (".microsoft");
// at this point _Bx._Buf content is msdn.microsoft, _Bx._Ptr is bad ptr
b.append (".com");
// at this point _Bx._Buf content is msdn.microsoft.com, _Bx._Ptr content is msdn.microsoft.com
return b;
}
int main()
{
string s1 = foo();
return 0;
}
thanks in advance,
George
|