C + + Memory Management

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.