1

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

4
  • 1
    if you tell us why you would want to, there's a greater chance someone could offer you an alternative solution as well. Commented May 4, 2011 at 7:41
  • I am getting a crash while creating an STL string object. But I cannot identify the root cause of the issue. There are may stlstring objects shared by multiple threads. I want to narrow the debugging process by allocating memory for each stl string object from the heap Commented May 4, 2011 at 7:43
  • does your code run fine if you omit creation of stl::string objects? Commented May 4, 2011 at 7:52
  • 2
    Trust me, you don't want to do this . The only real way to debug multi-threaded code is to sit down, away from the computer, and think hard, not to start adding more layers of code that could have bugs. The standard library will have been far more thoroughly debugged than anything you are likely to write. Commented May 4, 2011 at 7:53

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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?

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.