Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > std::string and refcounting

Reply
Thread Tools

std::string and refcounting

 
 
Michiel Salters
Guest
Posts: n/a
 
      04-22-2004
Alexander Terekhov <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> Michiel Salters wrote:
> [...]
> > A site that addresses the basics is www.gotw.ca, especially GOTW
> > articles #43-#45. The executive summary: refcounting is too hard in
> > threaded environments, and even in single-threaded environments
> > typically provides little if any advantage.

>
> First off, it isn't really too hard.


I think we're talking about two things. You probably interpreted it
as "too hard to implement correctly" while I meant "too hard to
implement correctly and still faster than comparable non-refcounted".

> As for advantage... if deep copying needs to allocate memory
> (small string optimisations aside for amoment), it simply means
> that you'll incur "some" synchronisation overheard in the
> allocator instead of one single "naked" atomic increment without
> any membars on refcount.


True. COW obviously shines in the absence of W. Of course, the common
CHAR_T& STRING:perator[](pos_type) might very well be a write, which
causes branches and possibly copies in COW-types.

> #43-#45 is rather interesting reading but don't believe
> everything (especially conclusions) that it says.


Indeed. The best string class can only be found by profiling.
Until that time, stick with std::string. It is universally available,
and in general recent versions are pretty good for common cases.
It also has the added advantage of being able to use
platform-specific tricks in the implementation without sacrificing
portability, something your code can never achieve

Regards,
Michiel Salters
 
Reply With Quote
 
 
 
 
Alexander Terekhov
Guest
Posts: n/a
 
      04-22-2004

Michiel Salters wrote:
[...]
> True. COW obviously shines in the absence of W. Of course, the common
> CHAR_T& STRING:perator[](pos_type) might very well be a write, which
> causes branches and possibly copies in COW-types.


Use "const CHAR_T& STRING:perator[](pos_type) const" for reads.

regards,
alexander.
 
Reply With Quote
 
 
 
 
Peter van Merkerk
Guest
Posts: n/a
 
      04-22-2004
> > #43-#45 is rather interesting reading but don't believe
> > everything (especially conclusions) that it says.

>
> Indeed. The best string class can only be found by profiling.


For a given case and a given platform. It is not realistic to expect for a
string implementation to produce optimal results in every case, a trade off
has to be made somewhere.

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


 
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
if and and vs if and,and titi VHDL 4 03-11-2007 05:23 AM
refcounting errors??? hannibal.holm@gmail.com Python 2 11-03-2006 03:23 PM
Advanced topics... optimising / C++ / OOP / RefCounting / type-safety st_ev_fe@hotmail.com C++ 4 11-15-2005 12:35 PM
refcounting Simon Dahlbacka Python 2 04-14-2004 06:09 AM
refcounting and protecting against delete Pierre Phaneuf C++ 1 04-04-2004 02:28 AM



Advertisments