char,string,CString : which performance is best?? 
Author Message
 char,string,CString : which performance is best??

Hi:
i will write a program. i hope that the program have  best performance
which type of string will i selected?

thx very much:-)



Fri, 24 Dec 2004 11:23:48 GMT  
 char,string,CString : which performance is best??
CString is part of MFC. If your application uses MFC, then only you should
use CString. It would not make much sense to load the whole MFC library just
for CString.

String is useful in non MFC program. It is part of STL and provides you lot
of functionality of CString. If you are writing a program in C++, you should
use String.

char comes from C but is used in C++ programs also. If you plan to use C
string functions like strcpy, strcmp, you will need char one place or the
other.

Hope it was some help to you.

- Sumit.


Quote:
> Hi:
> i will write a program. i hope that the program have  best performance
> which type of string will i selected?

> thx very much:-)



Fri, 24 Dec 2004 14:26:06 GMT  
 char,string,CString : which performance is best??

Quote:

> CString is part of MFC. If your application uses MFC, then only you
> should use CString. It would not make much sense to load the whole
> MFC library just for CString.

One does not need to 'load the whole MFC library' to use CString any more
than one needs to 'load the whole STL' to use std::string.

CString may well be more efficient that std::string in current compiler/STL
versions, because it's refcounted, where the current STL isn't.

Quote:
> String is useful in non MFC program. It is part of STL and provides
> you lot of functionality of CString. If you are writing a program in
> C++, you should use String.

If you're interested in portability, then CString is definitely bad.  It's
richer than std::string, though, so you may find you have to write more code
yourself with std::string than you would with CString.

The answer is that you need to see what functionality you need, look at your
portability requirements and then benchmark the performance (if that's
relevant to your application).

Will



Fri, 24 Dec 2004 16:47:16 GMT  
 char,string,CString : which performance is best??

Quote:

> > CString is part of MFC. If your application uses MFC, then only you
> > should use CString. It would not make much sense to load the whole
> > MFC library just for CString.

> One does not need to 'load the whole MFC library' to use CString any more
> than one needs to 'load the whole STL' to use std::string.

Personally, whenever I need CString (which generally I don't because
std:string is just as good for most things), I use the version from the
Windows Template Library (WTL). The MFC CString does have certain
dependencies and MFC itself has a whole bunch of stuff that gets linked in
even if you don't need it (note: I'm not saying that *the whole* MFC needs
to be linked in, just minor parts that are even so irrelevant).

Loz.



Fri, 24 Dec 2004 18:41:28 GMT  
 char,string,CString : which performance is best??

Quote:

> Personally, whenever I need CString (which generally I don't because
> std:string is just as good for most things), I use the version from
> the Windows Template Library (WTL). The MFC CString does have certain
> dependencies and MFC itself has a whole bunch of stuff that gets
> linked in even if you don't need it (note: I'm not saying that *the
> whole* MFC needs to be linked in, just minor parts that are even so
> irrelevant).

I think this has been improved in VC7 - the CString has been combined
between MFC/ATL, so things have been cleaned up a bit.

I'm afraid I still prefer sprintf type formatting to streams, and things
like Replace and Tokenize (new to VC7) require much more work with the STL
class than with MFC.

Will



Fri, 24 Dec 2004 19:46:11 GMT  
 char,string,CString : which performance is best??
Try this link:

http://www.utilitycode.com/str


Quote:
> Hi:
> i will write a program. i hope that the program have  best performance
> which type of string will i selected?

> thx very much:-)



Fri, 24 Dec 2004 23:19:18 GMT  
 char,string,CString : which performance is best??

Quote:
> If you're interested in portability, then CString is definitely bad.  It's
> richer than std::string, though, so you may find you have to write more
code
> yourself with std::string than you would with CString.

Actually it's not richer. It may have a utility function or two that
"std::string" doesn't have but they're easily reproduced with "std::string"
(and likely with better results). More importantly, since "std::string" also
works with the STL algorithms, it's inherently more powerful - assuming
one's comfortable with the (potentially) cryptic syntax that is STL.


Sun, 26 Dec 2004 07:29:38 GMT  
 char,string,CString : which performance is best??

Quote:

> Actually it's not richer. It may have a utility function or two that
> "std::string" doesn't have but they're easily reproduced with
> "std::string" (and likely with better results).

OK.  'Richer' is clearly subjective.   I meant that if you want to use
printf formatting, do search and replace, do end trims, do tokenisation or
do case conversion, you'll find that you have to write code with std::string
which you didn't with CString.  Given that the aim of these utility classes
is to avoid one having to endlessly rewrite boilerplate code, I don't see
how having to write a helper function for std::string is a 'better result'
than using a pre-existing one for CString.

Quote:
> More importantly,
> since "std::string" also works with the STL algorithms, it's
> inherently more powerful - assuming one's comfortable with the
> (potentially) cryptic syntax that is STL.

I think we'd better agree that they have some overlapping functionality and
some differing functionality.   If you don't care about portability, you
might as well chose the one for which you have to roll fewest of your own
functions.

I use both, but I'm irked by having to write things for std::string which
were there in CString.   Indeed, some of them are there in the original C
library (e.g. strtok), which is particularly irksome.

Will



Sun, 26 Dec 2004 16:15:20 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. char,string,CString : which performance is best??

2. CString to Char and Char to CString

3. char[100] to CString and CString to char[100] again

4. Best way to create a BSTR from a CString or char*

5. storing a char string into a CString

6. CString to char string

7. Cstring to char or adding return/new line to string

8. string, CString, and char*

9. best way add chars to a string

10. char * to wchar_t (char string to wide string)

11. (Multiple) converting type list char/CString/char[]

12. (Multiple) converting type list char/CString/char[]

 

 
Powered by phpBB® Forum Software