Primitives
The use of the allocator is called directly.
Memory management is managed with a memory pool.
The new expression is divided into a few steps.
Allocated memory Returns a void * type
Type conversions, calling static_cast for type conversions
Calling the constructor directly calls the constructor only if the compiler can call directly, and you need to call placement new to construct the object on the object address.
Returns the address that points to the object.
The above operator new source code is the use of a For loop to keep the memory of malloc, if the direct success, directly return, if the failure, the call you set the memory allocation failure to perform the action, which is provided by C + + in the memory allocation failure of the mechanism. This function is guaranteed not to throw an exception, c++11 can use the new feature of Noexcept.
The process of delete first calls the destructor and then releases the memory.
String in the standard library is a typedef, the real name is basic_string.
The memory leak referred to here is caused by a destructor not being called. Instead of the array itself, this situation is not caused by a call to the destructor.
When the array new expression is used, there is no chance of starting the object's initial value, so a default constructor is required to initialize the data.
The memory layout under VC6.
The size of the array is written to the cookie in the memory block, so it takes up more memory resource space.
C + + Memory Management