C ++ Memory Object Management

Source: Internet
Author: User

Let's take a moment back from placement new to see the relationship between the new operator and operator new. To create an object on the stack, you should use the new operator. It allocates both memory and calls constructors for objects. If you only want to allocate memory, you should call the operator new function; it will not call the constructor. If you want to customize your memory allocation process when the heap object is created, you should write your own operator new function and then use the new operator, the new operator will call your customized operator new. if you want to create an object in a memory with obtained pointers, you should use placement
New.

 

In C ++

A * A = new ();

Perform the following operations in two parts:

Part 1:

Call the oprator new (size_t size) function to allocate memory.

Call constructor ()

 

Oprator new (size_t size)

The compiler will check whether a has rewritten the function. If not, it will call the global operator new () function.

 

Therefore, if you want to change the memory allocated by the system to the object on the stack, you must control the memory allocated by yourself.Algorithm. Rewrite the operator new () function.

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.