![]() |
CString function parameter |
Post Reply
|
| Author | |
jimmy
Senior Member
Joined: 11 November 2003 Location: Austria Status: Offline Points: 516 |
Post Options
Thanks(0)
Quote Reply
Topic: CString function parameterPosted: 23 January 2006 at 4:30am |
|
Hello CodeJock Team,
1) the codejock software is great. 2) optimize point a big part of the software have FunctionName(CString strParam) but it is better use FunctionName(const CString& strParam) The software ist much faster, less memory defragmentation, smaller code size. Please, change this for the next release. also look for other function parameter, to add the parameter as const referenz. Jimmy |
|
![]() |
|
Oleg
Senior Member
Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
Post Options
Thanks(0)
Quote Reply
Posted: 24 January 2006 at 1:56pm |
|
Hi, 1. Agree :) Thank you 2. Actually in 9.81 we changed most of "CString strParameter" to "LPCTSTR lpszParameter" some virtual methods we can't change to avoid your complains about compatibility ;)
|
|
|
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS |
|
![]() |
|
jimmy
Senior Member
Joined: 11 November 2003 Location: Austria Status: Offline Points: 516 |
Post Options
Thanks(0)
Quote Reply
Posted: 25 January 2006 at 5:09am |
|
Hi oleg,
LPCTSTR is also not good, because if you do m_strCaption = lpszParameter it always make a strlen, alloc. It's slow, and higher memory defragmentation. For compatibility it's ok. But for new, i think const CString& is the best solution. Jimmy |
|
![]() |
|
Oleg
Senior Member
Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
Post Options
Thanks(0)
Quote Reply
Posted: 25 January 2006 at 8:49am |
|
lets see. if method declared as SomeMethods(cont CString& strItem) and called as SomeMethod(_T("SomParameter")); anyway compiller first create CString variable and assign it with "SomParameter", and later destroy it.
|
|
|
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS |
|
![]() |
|
Warren
Groupie
Joined: 23 February 2005 Status: Offline Points: 64 |
Post Options
Thanks(0)
Quote Reply
Posted: 07 February 2006 at 10:30am |
|
Jimmy, You said "...LPCTSTR is also not good..." but according to Microsoft: "...in most cases it is best to declare the string function parameter as LPCTSTR..." |
|
![]() |
|
jimmy
Senior Member
Joined: 11 November 2003 Location: Austria Status: Offline Points: 516 |
Post Options
Thanks(0)
Quote Reply
Posted: 12 February 2006 at 8:21am |
|
Hi,
1) if i call a function many time, i use static CString s_strText(_T("My Text")); Function( s_strText ); And void Function( const CString& strText ); So it must alloc the text only one time. In some function i use also (LPCTSTR lpText), but only if it call not often. also use as return parameter const CString& GetName() { return m_stName; } The most time if you call GetName (or other) is, to put the paramter to other function. x.SetName( y.GetName() ); So this is much faster than always create a new CString. If i look into our program code, 95 percent of function call put a CString as parameter. Jimmy |
|
![]() |
|
Warren
Groupie
Joined: 23 February 2005 Status: Offline Points: 64 |
Post Options
Thanks(0)
Quote Reply
Posted: 12 February 2006 at 4:37pm |
|
Are you under the impression that CString allocates a new copy of the
text, and copies the text into the new buffer each time you return "CString" instead of "const CString&"?
Because that is not how it works.
AFAIK, CString has a COW (copy on write) implementation, so what are you really saving? It's basically: return 1 pointer/reference vs. change reference count, return 1 pointer/reference Either way, I wouldn't worry about it nowadays. With 2+ Ghz computers, 99% of optimization is algorithmic and not tweaking code. That's just my 2 cents... |
|
![]() |
|
Post Reply
|
|
|
Tweet
|
| Forum Jump | Forum Permissions ![]() You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |