Click to See Complete Forum and Search --> : space in string


George2
February 26th, 2008, 08:23 PM
Hello everyone,


The space in string should use heap address memory space, not stack, right? But through debugging, for example,


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

angelorohit
February 27th, 2008, 02:49 AM
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(). :rolleyes:

treuss
February 27th, 2008, 03:33 AM
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.

George2
February 27th, 2008, 04:13 AM
Thanks treuss,


My question is answered.

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