Re: CString Speed and compiler optimization
From: Richard Formby (rf302_at_cueword.com.au)
Date: 03/13/04
- Next message: bayX: "Re: CDC"
- Previous message: Jase: "Re: Length of Text"
- In reply to: Marc Lefebvre: "CString Speed and compiler optimization"
- Next in thread: Joseph M. Newcomer: "Re: CString Speed and compiler optimization"
- Messages sorted by: [ date ] [ thread ]
Date: Sat, 13 Mar 2004 09:51:19 GMT
"Marc Lefebvre" <Marc__Lefebvre_pub_NOSPAM@hotmail.com> wrote in message
news:usFgXULCEHA.1128@TK2MSFTNGP11.phx.gbl...
> CString strTemp;
> strTemp = ""; Can you tell me if the compiler optimization
remove
> this affectation ?
No, it would not. [1]
> If I have a member variable in a class (m_strTemp)
> If I put the following line in the constructor
> m_strTemp = "";
>
> Can you tell me if the compiler optimization remove this affectation ?
No, it would not. [1]
> What was the vest way to have an empty string?
>
> strTemp = "";
> or
> strTemp.Empty
Look at the code for CString::operator=(TCHAR *) and CString::Empty(); and
decide for yourself but...
Empty checks for a few things and does a bit of stuff to release, or not,
the underlying storage.
operator= checks (with some function I didn't delve into) if the string
being assigned has zero length. If it does then operator= calls Empty. Hmmm.
Empty is, by definition, quicker.
However, why this interest in what the optimiser does. You yourself can
destroy any benefit the optimiser does by simply, say, initialising a
variable in the wrong place (inside a loop). Also, I have seen people spend
days optimising code by hand that is only called once in an applications
lifetime.
[1] The compiler optimises nearby code, usually at the assembler level. It
has no idea about the other code that may be in a class. In particular it
has no way to know that a CString is initialised, in its constructor, to
empty, so how would it know that assigning an empty string to a freshly
constructed CString is superfluous?
Cheers
Richard.
- Next message: bayX: "Re: CDC"
- Previous message: Jase: "Re: Length of Text"
- In reply to: Marc Lefebvre: "CString Speed and compiler optimization"
- Next in thread: Joseph M. Newcomer: "Re: CString Speed and compiler optimization"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|
|