5 ms·
Are you sure about that? I don't really know the internals, but I would assume the implementation looks something like: Let the compiler put the array (of chara
by aston 19y ago
Are you sure about that? I don't really know the internals, but I would assume the implementation looks something like: Let the compiler put the array (of characters or numbers) somewhere where I can get them, and I'll take that pointer and keep it in my stack-allocated STL data structure.
Any references that say you're right?
- mojuba 19y agoThe 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