I am reading a book Efficient C++: Performance Programming Techniques Authors is saying following regarding global new and delete operators:
They manage memory in the process context, and since a process may spawn multiple threads,
new()
anddelete()
must be able to operate in a multithreaded environment. In addition, the size of memory requests may vary from one request to the next.
in Chapter 6. Single-Threaded Memory Pooling.
Is this true? I thought C++ does not have a notion of a Multi-threading environment, programmer need to handle is by using some means of mutual exclusion.
It will depend on implementation. For example, Visual C++ runtime had both a single-threaded and a multithreaded version of heap in earlier version, but starting with Visual C++ 2005 it only has a multithreaded version. This MSDN article has a nice summary table.
When a multithreaded heap is used calls to memory allocation and deallocation are thread-safe at expense of additional overhead.