What is C + + new exactly new?

Source: Internet
Author: User

9:int *obj = new int (6); 00F714CE push 4//press stack 00f714d0 call operator new (0F711EAH)//Invoke new function to return assigned address addr---0f711eah is instruction JM P operator new Address 00F714D5 add esp,4//recovery stack 00f714d8 mov dword ptr [EBP-0F8H],EAX//Return address addr assigned to the memory space ebp-0f8h from the start address 00F714DE C MP DWORD ptr [ebp-0f8h],0//Determine if the assignment was successful 00f714e5 JE main+51h (0f71501h)//If not successfully jumped to 0x0f71501h 00F714E7 mov eax,dword ptr [ebp -0F8H]//Start address is ebp-0f8h memory space (addr) assigned to eax00f714ed mov dword ptr [eax],6//Put the memory space with the starting address of eax (addr) into 600F714F3 mov Ecx,dword PTR [ebp-0f8h]//Start address is ebp-0f8h memory space (addr) assigned to ECX00F714F9 mov dword ptr [EBP-100H],ECX// The value of ecx (addr) is assigned to the memory space where the start address is ebp-100h 00f714ff jmp main+5bh (0F7150BH)//unconditional jump to 0x0f7150b00f71501 mov dword ptr [ebp-100h],0// The memory space with the starting address of ebp-100h is set to 0---allocation fails 00f7150b mov edx,dword ptr [ebp-100h]//Start address ebp-100h memory space (addr) assigned to EDX00F71511 MOV DWORD ptr [Obj],edx//addr The content of edx to the memory space where obj is the starting address a10:delete obj;00f71514 mov eax,dword ptr [obj]//The memory space where obj is the starting address is sent to EA x00f71517 mov dword ptr [Ebp-0ech],eax//eax sent to Ebp-0ech as the starting address of the memory space 00f7151D mov ecx,dword ptr [Ebp-0ech]//memory space with Ebp-0ech as the starting address sent to ecx00f71523 push ecx//ECX stack 00f71524 call operator delete (0f710a0 h) 00f71529 Add esp,4 11:int *obj2 = new int (7), same as allocation obj

  

At this point the output *obj, you will get "7". Why? Obj would have been to point to the assigned address addr_obj, deleting the contents of the addr_obj, releasing the addr_obj memory, but obj itself points to it when we allocate space for OBJ2, the new function returns the first available address. This is the addr_obj that was released just now, and obj still points to that address, so I get the result. This is done occasionally correctly, but endless!!! The addr of the placeEAX, ptr [ebp-0f8h], ecx, ptr [ebp-100h], edx, Ptr[obj]   What the new function has to do1. Call the object's constructor, allocate space, and return the address ADDR2. Assigns the returned address addr to the pointer object

What is C + + new exactly new?

Related Article

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.