-
April 9th, 2010, 11:44 AM
#1
Substring
How does substr() in the string class work?? Does it copy over each character linearly?
Thanks in advance
-
April 9th, 2010, 11:55 AM
#2
Re: Substring
It probably depends on the implementation. A reference-counted copy-on-write implementation is possible, although I think the next version of the standard will require substr() to actually make an O(n) copy, yes. (Trying to use copy-on-write in conjunction with multithreading would be....interesting.)
-
April 9th, 2010, 05:53 PM
#3
Re: Substring
Yes, here's a way to show:
Code:
std::string test("Hello World");
std::cout << (void*)test.data() << " - " << (void*)test.substr(0, 5).data() << std::endl;
If they're the same they're copy on write, else, literal copy.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|