Best way to duplicate a String



I want to use a string in a thread. Because the thread is only reading the string, I would prefer not to add a lock for reading the string.

So, I thought about storing a copy of the string inside the thread class.
What the best way to duplicate a string (and make sure the real data is actually copied, not just refcounted) ?


If you cast it to a const tchar*, and make a string from that, it’ll definitely copy it.


I’m thinking about it, but because you’re using atomic refcounting, it shouldn’t matter if it’s a refcounted pointer, right ?

In other words, is the string class thread safe ?


Well yes, I wrote it to be thread-safe. But I’ve never quite trusted it for some reason… I just never quite feel safe without a critical section being involved.