|
-
February 26th, 2008, 09:23 PM
#1
space in string
Hello everyone,
The space in string should use heap address memory space, not stack, right? But through debugging, for example,
Code:
string str = "hello";
why I can not see the invocation of new operator? Anyone could point out where STL string class allocates space on heap and using which function to allocate please (any other approach other than using new to allocate space on heap?)?
thanks in advance,
George
-
February 27th, 2008, 03:49 AM
#2
Re: space in string
Yes the space in an std::string is allocated on the heap. It uses the new operator for this. I can't really think of any other decent way to dynamically allocate memory in C++. Well, there is malloc().
-
February 27th, 2008, 04:33 AM
#3
Re: space in string
 Originally Posted by George2
The space in string should use heap address memory space, not stack, right?
There is nothing in the standard stating any requirement for how std::string allocates memory. Most implementations will use stack memory for small strings and heap memory for large ones.
More computing sins are committed in the name of efficiency (without necessarily achieving it) than for any other single reason - including blind stupidity. --W.A.Wulf
Premature optimization is the root of all evil --Donald E. Knuth
Please read Information on posting before posting, especially the info on using [code] tags.
-
February 27th, 2008, 05:13 AM
#4
Re: space in string
Thanks treuss,
My question is answered.
 Originally Posted by treuss
There is nothing in the standard stating any requirement for how std::string allocates memory. Most implementations will use stack memory for small strings and heap memory for large ones.
regards,
George
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
|