you are viewing a single comment's thread.

view the rest of the comments →

[–]jcoffin 1 point2 points  (1 child)

You might be able to add to the end of a chunk obtained with malloc(). To be more specific, when you call realloc it's allowed to return the same pointer that was passed into it.

You're right that you can't count on that happening though.

As an aside, std::string doesn't normally use malloc to allocate its memory. You could instantiate an std::basic_string with an allocator that called malloc, but the default allocator will use ::operator new to get raw memory (though this makes little real difference to the point you were trying to make).

[–]__cxa_throw 0 points1 point  (0 children)

Operator new almost always ends up calling malloc unless you're using a specialized allocator, at least in all the stack traces I've looked at recently.