Does std :: cout fully work on the stack?

In C ++, when I use std::cout as follows:

 std::cout << "myString" << std::endl; 

Is there anything that will be allocated on the heap on std :: cout? Or std :: cout will do everything on the stack (which means that std :: cout and its basic functions will not execute any new/malloc/etc... )?

I want to know if using std :: cout can heavily cause heap fragmentation

+7
source share
2 answers

In this particular example, your code does not cause any direct allocations on the heap. However, you can use any method to use the heap for part of its work. This is great if the implementation of the method is correctly cleared after itself.

This logic applies to methods such as operator<<(std::ostream&, T) .

+7
source

It completely depends on the specific implementation of the C ++ core libraries

+5
source

All Articles