From: http://blog.csdn.net/zhihuizhilv/article/details/5388946
Vc2003 DevelopmentProgram, Encountered a crash problem, after a hard query, found that and STD: String memory management and their usage.
STD: String uses a lazy memory management policy. For example:
String str1 = "sdsada ";
String str2 = str1;
At this time, the two objects refer to the same memory string. That is to say, when str2 is constructed through str1, str2 does not immediately allocate a piece of its own string memory, but directly uses str1, and adds the reference number of this memory to 1.
What is incredible is that STD: String does not consider the concurrency of multithreading, which may cause problems when operating string objects with shared string memory among multiple threads.
To avoid this risk, we can only ensure that the string objects operated by multiple threads do not share the string memory. AboveCodeIs:
String str2 = str1.c _ STR ();
Can solve the problem.
You can also use cstring to skip this issue.