Re: Please help with testing & improving a StringValue class
* Gianni Mariani:
Alf P. Steinbach wrote:
...
Comments, ideas, criticism etc. welcome!
Is it thread safe?
In addition to my previous reply, in version 05 (I guess that will be
0.05!) I've added
void detach()
{
if( refCount() > 1 ) { doDetach( capacity() ); }
assert( refCount() <= 1 );
}
StringValue_& detached()
{
detach();
return *this;
}
so that a "detached" instance, not sharing data with any other instance,
can be easily created for passing to another thread. The cost is
possible dynamic allocation and O(n) copying, depending on the current
ref-count of the source. I haven't tested this except that doDetach is
used in operator+= and seems to work well.
None of the versions have used static variables, but of course the code
uses dynamic allocation, which depending on the run-time library may use
thread unsafe static variables: that aspect is the same as with any
other C++ code, and with the current standard very tool-specific.
Btw., I've posted version 05 (also supporting operator+= concatenation,
with time generally linear in the argument instead of linear in the
result) at <url: home.no.net/alfps/cpp/lib/alfs_v05.zip>, Boost license.
Cheers,
- Alf
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?