memset structure with std::string contained

Viewed 8679

I have a massive structure where the entire contents is scalar variables, enumerations, and arrays of scalars (stack-based) with the exception of one std::string variable.

Now, here's my question...

Can I memset the structure to 0 for its whole size (like I would if it was simply all scalars), or is that not possible with the std::string being in there? I'm not sure what memset would do to its internal representation.

And if you're going to say its good/bad please explain why - I'd like to know why it is the way it is :)

3 Answers

Zeroing std::string member is very bad idea, it will cause memory leak! Never do this!

Related