c ++ deep copy problem

Recently doing a project, netsdk will throw up information data to the application layer, the data type is void *, then the top will convert the data into stuFace_info type, such as

typedef struct tagFaceData
{
 int iEventID;
 char name[64];
 char *info;

int infoLen;
}stuFace_info;

When the beginning of the process, I like this conversion stuFace_info * pInfo = (stuFace_info *) info; interrupted at this time point found} stuFace_info data are normal, but I will pInfo into the message queue inside, and transmitted to the other when the module, acquiring data found wrong, and finally found no deep copy, immediately added

char * sImpnfo = new char [pInfo-> infoLen];

memcopy (sImpnfo -> info, (stuFace_info *) info-> info, (stuFace_info *) info-> infoLen)); to solve the problem.

Conclusion is that when a string of words appeared, the structure, the copies of the string to be deep copy, if shallow copy, then just copy the desired location.

 

 



Guess you like

Origin blog.csdn.net/songzhaorong/article/details/78823831