Click here to Skip to main content
15,916,188 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Questionmember variable of STL string class Pin
George_George20-Aug-08 23:17
George_George20-Aug-08 23:17 
AnswerRe: member variable of STL string class Pin
toxcct20-Aug-08 23:51
toxcct20-Aug-08 23:51 
GeneralRe: member variable of STL string class Pin
George_George21-Aug-08 0:01
George_George21-Aug-08 0:01 
GeneralRe: member variable of STL string class Pin
toxcct21-Aug-08 0:03
toxcct21-Aug-08 0:03 
GeneralRe: member variable of STL string class Pin
George_George21-Aug-08 0:21
George_George21-Aug-08 0:21 
AnswerRe: member variable of STL string class Pin
CPallini20-Aug-08 23:52
mveCPallini20-Aug-08 23:52 
GeneralRe: member variable of STL string class Pin
George_George21-Aug-08 0:08
George_George21-Aug-08 0:08 
GeneralRe: member variable of STL string class Pin
CPallini21-Aug-08 0:33
mveCPallini21-Aug-08 0:33 
George_George wrote:
1.

So, your answer to my question 1 is _Buf is used to hold small sized content, and _Ptr is used to hold larger sizes content. Small sized content is on stack and larger sized content is on heap, correct?

Yes (and, as I stated that is a clever and desiderable behaviour).

George_George wrote:
2.

What is your answer to my original question item 2? I think because when the content is small, only _Buf is used and _Ptr is empty, so _Ptr is bad ptr? Correct understanding?


It is a bit more subtle: since _Buf & _Ptr share the same (at least sizeof(_Ptr)) memory locations, because both of them belongs to a union, hence _Prt is a bad pointer when
(1) The context requires _Buf usage (i.e. short string).
(2) the initial characters of the string (for instance {_Buf[0], _Buf[1], _Buf[2], _Buf[3]} for ANSI strings), interpreted as a pointer, give an invalid address.
For instance the following code
union Foo
{
  char a[4];
  char *p;
};
void main()
{
  Foo f;
  f.a[0]='m';
  f.a[1]='s';
  f.a[2]='d';
  f.a[3]='n';
}


(as side effect) assigns 0x6e64736d, i.e. an invalid address to f.p.
Smile | :)

If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.

This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke

[My articles]

GeneralRe: member variable of STL string class Pin
George_George21-Aug-08 0:43
George_George21-Aug-08 0:43 
GeneralRe: member variable of STL string class Pin
CPallini21-Aug-08 0:48
mveCPallini21-Aug-08 0:48 
GeneralRe: member variable of STL string class Pin
George_George21-Aug-08 19:38
George_George21-Aug-08 19:38 
GeneralRe: member variable of STL string class Pin
CPallini21-Aug-08 21:36
mveCPallini21-Aug-08 21:36 
GeneralRe: member variable of STL string class Pin
George_George21-Aug-08 21:49
George_George21-Aug-08 21:49 
GeneralRe: member variable of STL string class Pin
CPallini21-Aug-08 22:07
mveCPallini21-Aug-08 22:07 
GeneralRe: member variable of STL string class Pin
George_George21-Aug-08 22:50
George_George21-Aug-08 22:50 
GeneralRe: member variable of STL string class Pin
CPallini21-Aug-08 23:13
mveCPallini21-Aug-08 23:13 
GeneralRe: member variable of STL string class Pin
George_George21-Aug-08 23:51
George_George21-Aug-08 23:51 
AnswerRe: member variable of STL string class Pin
Nemanja Trifunovic21-Aug-08 3:58
Nemanja Trifunovic21-Aug-08 3:58 
GeneralRe: member variable of STL string class Pin
George_George21-Aug-08 19:40
George_George21-Aug-08 19:40 
QuestionThe Problem about DataGrid and Adodc Pin
aygrhnwms30420-Aug-08 22:49
aygrhnwms30420-Aug-08 22:49 
AnswerRe: The Problem about DataGrid and Adodc Pin
aygrhnwms30421-Aug-08 2:30
aygrhnwms30421-Aug-08 2:30 
QuestionAutomatic installation procedure question Pin
monsieur_jj20-Aug-08 21:37
monsieur_jj20-Aug-08 21:37 
AnswerRe: Automatic installation procedure question Pin
KarstenK20-Aug-08 22:20
mveKarstenK20-Aug-08 22:20 
GeneralRe: Automatic installation procedure question Pin
monsieur_jj20-Aug-08 23:04
monsieur_jj20-Aug-08 23:04 
GeneralRe: Automatic installation procedure question Pin
Rajesh R Subramanian20-Aug-08 23:17
professionalRajesh R Subramanian20-Aug-08 23:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.