|
-
December 3rd, 2004, 11:44 AM
#10
Re: Usage of static const
 Originally Posted by Graham
It's hard to give an accurate description, because there are no specific rules laid down by the standard for implementaion of string. It's possible to write a "lazy" implementation that reference counts strings (makes for quick copies) and that only makes a separate copy if you do something to modify one of them. used to initialise it until such time as you call a mutator function, and only then does it copy it to the heap. I'm not saying it will, just that the rules allow it. There's quite a lot of flexibility there.
Even with reference counting, (which most implementations have) the memory storing the string data would still be placed on the heap.
(***not referring to string literal***).
 Originally Posted by Graham
It's possible that an implementation could point directly to the literal
That would be very difficult for an implementation to do. The std::string constructor would have to know that it's pointing to a string literal.
There is a common version of std::string who's data can be completely on the stack for small strings.
One common implementation of std::string creates a static size buffer used for small strings. This buffer is usually about 16 characters or less.
If the string size is larger then the static buffer, then a dynamic buffer is used which is again placed on the heap.
Anyway, both of you are missing the entire point of my original post.
The point I was making is the just because an object is constant, doesn't mean that the entire object is created on the stack.
If the object has dynamic data, the dynamic data can be on the heap.
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
|