STL optimizes memory allocation for string objects by providing memory for string objects from a memory开发者_开发知识库 pool kept by the standard library. Is it possible to disable this optimization?
I am using VS 2008
No, you can't. From the C++ reference on string::string:
Except for the copy constructor, an optional final parameter exists for all basic_string constructors, whose type is its Allocator template argument. This parameter influences the memory allocation model to be used for the object. To provide a better readability, and because under no known compiler implementation the memory allocation model for strings (allocator) is affected by its value, it has not been included in the declarations above, but see the basic template member declaration ahead for a more complete declaration.
The following question will help you in understanding how the std::basic_string
can be manipulated to be used with various allocators
How do I allocate a std::string on the stack using glibc's string implementation?
精彩评论