samedi 28 février 2015

std::string and const char *

If I use



const char * str = "Hello";


there is no memory allocation/deallocaton needed in runtime


If I use



std::string str = "Hello";


will be there an allocation via new/malloc inside string class or not? I could find it in assembly, but I am not good at reading it.


If answer is "yes, there will be malloc/new", why? Why can there be only pass through to inner const char pointer inside std::string and do actual memory allocation if I need to edit edit string?


Aucun commentaire:

Enregistrer un commentaire