| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
||||
|
||||
|
Short version: Implementation defined: Don't rely on it, especially when you switch compiler or compiler version (including service packs etc)
Long version: I'm assuming your findings are real and correct. Quote:
Quote:
The requirement is that its public members and functions behave as the C++ standard says it has to. Beyond that, everyone is free to implement it in the way they please. (And that pleases their customers...) Keeping small strings close is a good speed boost because it increases the chance of it being in cache ahead of time. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > Member variable of STL string class |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|