3 ms·
The best reference is the source code. Let's look at the string. In C/C++ there is no reliable and portable way for your program to find out whether some (char
by mojuba 19y ago
The best reference is the source code.
Let's look at the string. In C/C++ there is no reliable and portable way for your program to find out whether some (char*) points to a constant string literal or not. So the only oprion for a dynamic string implementation is to always copy any data the constructor receives to somewhere else, normally to the dynamic memory. As a result, any initialization involves dynamic allocation and copying of data in C++.
At the same time languages that have built-in support for dynamic structures avoid this by creating proper structures in the constant segment. So a statement like string s = "abc" would do nothing but assign a pointer.
This is a huge problem in C++ and even C++0x doesn't solve it unfortunately.
- jey 19y agoC++0x introduces move constructors. http://www.google.com/search?q=move+constructors+c%2B%2B0x http://www.google.com/search?q=move+constructors+c%2B%2B0x