Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Why is CString not preferred

Reply
Thread Tools

Why is CString not preferred

 
 
Rajesh Garg
Guest
Posts: n/a
 
      07-22-2003
Why and in what situations is CString not preferred?
RVG
 
Reply With Quote
 
 
 
 
Aggro
Guest
Posts: n/a
 
      07-22-2003
Rajesh Garg wrote:
> Why and in what situations is CString not preferred?
> RVG


CString is not part of the standard C++. If you want to use the code you
wrote for example in Linux or other non-windows system, you need to
first code it. And when you do that, you won't propably get as good
result as std::string is.

And even if you are not currently thinking that your code, or part of
its might be used on other system. That still might be the case in the
future. That's why IMHO you should try to make your code standard, if
there are not any good reason why not.

 
Reply With Quote
 
 
 
 
MG
Guest
Posts: n/a
 
      07-22-2003
> Why and in what situations is CString not preferred?

CString is not preffered as its pretty heavy in terms of string
manipulation..
e.g. it allows the "+" operation on strings...and ppl have tendency of using
the + operation lousily...
what they tend to forget is that this operation requires a memory
alloc...copying the strings and freeing the memory earlier used...

and its due to this reason...for good programming...CString should be
avoided..
MG


 
Reply With Quote
 
Karl Heinz Buchegger
Guest
Posts: n/a
 
      07-22-2003


MG wrote:
>
> > Why and in what situations is CString not preferred?

>
> CString is not preffered as its pretty heavy in terms of string
> manipulation..
> e.g. it allows the "+" operation on strings...and ppl have tendency of using
> the + operation lousily...
> what they tend to forget is that this operation requires a memory
> alloc...copying the strings and freeing the memory earlier used...
>
> and its due to this reason...for good programming...CString should be
> avoided..


what are you talking about?
CString is a string class like std::string or many other string classes
out there. It does it's job. And if the job requires 2 strings to be
catanated and the operator+ is the method to do it, well, then I guess
this is what needs to be done. And guess what: every string class you can
imagine will have to handle the case of allocating memory for the result,
this is nothing specific to CString.

The reason we don't talk about CString in this NG is that it is a
proprietary string class like many others. There is exactly one string
class which is standard and comes with every decent C++ compiler: std::string
Thats the one we talk about in that NG.


--
Karl Heinz Buchegger

 
Reply With Quote
 
MG
Guest
Posts: n/a
 
      07-22-2003

"Karl Heinz Buchegger" <> wrote in message
news:...
>
>
> MG wrote:
> >
> > > Why and in what situations is CString not preferred?

> >
> > CString is not preffered as its pretty heavy in terms of string
> > manipulation..
> > e.g. it allows the "+" operation on strings...and ppl have tendency of

using
> > the + operation lousily...
> > what they tend to forget is that this operation requires a memory
> > alloc...copying the strings and freeing the memory earlier used...
> >
> > and its due to this reason...for good programming...CString should be
> > avoided..

>
> what are you talking about?
> CString is a string class like std::string or many other string classes
> out there. It does it's job. And if the job requires 2 strings to be
> catanated and the operator+ is the method to do it, well, then I guess
> this is what needs to be done. And guess what: every string class you can
> imagine will have to handle the case of allocating memory for the result,
> this is nothing specific to CString.

right....
but the ease with which these things are available in CString that i have
seen people getting carried away and start using the heavy functions
lavishly without realising the load it has...


 
Reply With Quote
 
Karl Heinz Buchegger
Guest
Posts: n/a
 
      07-22-2003


MG wrote:
>
> >
> > what are you talking about?
> > CString is a string class like std::string or many other string classes
> > out there. It does it's job. And if the job requires 2 strings to be
> > catanated and the operator+ is the method to do it, well, then I guess
> > this is what needs to be done. And guess what: every string class you can
> > imagine will have to handle the case of allocating memory for the result,
> > this is nothing specific to CString.

> right....
> but the ease with which these things are available in CString


Please enlighten me. In which way is it easier to catanate 2 strings
with the help of CString then by using std::string?

> that i have
> seen people getting carried away and start using the heavy functions
> lavishly without realising the load it has...


.... and the very same holds true for every other string class.
So there is only one conclusion from what you are telling us:
don't use a string class at all.

But that's definitly not what one wants to do.

--
Karl Heinz Buchegger

 
Reply With Quote
 
Peter van Merkerk
Guest
Posts: n/a
 
      07-22-2003
> > but the ease with which these things are available in CString
>
> Please enlighten me. In which way is it easier to catanate 2 strings
> with the help of CString then by using std::string?
>
> > that i have
> > seen people getting carried away and start using the heavy functions
> > lavishly without realising the load it has...

>
> ... and the very same holds true for every other string class.
> So there is only one conclusion from what you are telling us:
> don't use a string class at all.


Users of the std::string class can use the reserve() function to reduce
the number of reallocations caused by for example concatenating strings.
This function can be added very easilly once it has been proven that
string concatenation is the performance bottleneck.

--
Peter van Merkerk
peter.van.merkerk(at)dse.nl


 
Reply With Quote
 
Tim Slattery
Guest
Posts: n/a
 
      07-22-2003
(Rajesh Garg) wrote:

>Why and in what situations is CString not preferred?
>RVG


It's available only through Microsoft's MFC classes. That makes it
proprietary and non-standard. If you're writing a program that will
run somewhere other than windows, you're not going to have access to
it. But you *always* have access to std::string, even if you're
writing an MFC program for Windows.

--
Tim Slattery

 
Reply With Quote
 
Rajesh Garg
Guest
Posts: n/a
 
      07-23-2003
Thanks Everybody....actually i was looking for the same kinda
discussion over the query. Its really helped.......though i am still
not clear WHEE does CString stand


"Peter van Merkerk" <> wrote in message news:<bfjapk$eveqc$>...
> > > but the ease with which these things are available in CString

> >
> > Please enlighten me. In which way is it easier to catanate 2 strings
> > with the help of CString then by using std::string?
> >
> > > that i have
> > > seen people getting carried away and start using the heavy functions
> > > lavishly without realising the load it has...

> >
> > ... and the very same holds true for every other string class.
> > So there is only one conclusion from what you are telling us:
> > don't use a string class at all.

>
> Users of the std::string class can use the reserve() function to reduce
> the number of reallocations caused by for example concatenating strings.
> This function can be added very easilly once it has been proven that
> string concatenation is the performance bottleneck.

 
Reply With Quote
 
Karl Heinz Buchegger
Guest
Posts: n/a
 
      07-23-2003


Peter van Merkerk wrote:
>
> > > but the ease with which these things are available in CString

> >
> > Please enlighten me. In which way is it easier to catanate 2 strings
> > with the help of CString then by using std::string?
> >
> > > that i have
> > > seen people getting carried away and start using the heavy functions
> > > lavishly without realising the load it has...

> >
> > ... and the very same holds true for every other string class.
> > So there is only one conclusion from what you are telling us:
> > don't use a string class at all.

>
> Users of the std::string class can use the reserve() function to reduce
> the number of reallocations caused by for example concatenating strings.
> This function can be added very easilly once it has been proven that
> string concatenation is the performance bottleneck.


This is an argumentation I can live with. But thats not what MG
claimed in the first place

--
Karl Heinz Buchegger

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
can someone tell me why ospf is being preferred over eigrp in thiscase? k65020@gmail.com Cisco 0 12-03-2007 07:23 AM
why why why why why Mr. SweatyFinger ASP .Net 4 12-21-2006 01:15 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
New to CString. Why won't this compile? Susan Rice C++ 4 12-01-2006 10:07 AM
Preferred Python idiom for handling non-existing dictionary keys and why? Quentin Crain Python 8 10-11-2003 12:16 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57