Re: Corresponding forms of new and delete

From: Dhruv (dhruvbird_at_gmx.net)
Date: 10/22/03

  • Next message: max: "Re: easy question part 2"
    Date: 21 Oct 2003 21:29:08 -0400
    
    

    On Mon, 20 Oct 2003 17:11:51 -0400, Dave wrote:

    >
    > Hello all,
    >
    > In the code below, I see the following output:
    >
    > base::operator new(size_t, int)
    > base::base()
    > base::~base()
    > base::operator delete(void *)
    >
    > In the case of an exception being thrown during construction, a form
    of
    > delete with a signature that corresponds to that of the "new" being
    used
    > will be called. However, during a "normal" deallocation, there is no
    way to
    > know which version of "new" was previously used, so the usual
    deallocation
    > routine is used (I hope I'm using the term "usual" properly here).
    This is
    > demonstrated in the output shown above.
    >
    > When the statement "delete ptr;" is reached, is there a way to cause
    it to
    > use "operator delete(void*, int)" as the underlying deallocation
    routine
    > rather than "operator delete(void *)"? After all, the usual
    dellaocation
    > routine may not do what's right given that the memory was not
    allocated with
    > the usual allocation routine! (Again, I hope I'm using the term
    "usual"
    > properly.)
    >

    No, there is no way that I am aware of that can make the operator delete
    that you want to be called to get called. This operator delete exists
    primarily because of potential failure of the object construction while
    calling operator new, as you have already mentioned, but if you want to
    call the operator new that takes extra parameters, then while deleting
    that object you have to manually do the destroy-deallocate dance. The
    reason for this is that you may pass pointers to functions that might
    delete this passed pointer, so how can the functions know which operator
    delete to call. So, you have to manually deallocate and delete the
    memory.

    > I am aware that I could do the following in place of "delete ptr;":
    >
    > ptr->~base();
    > base::operator delete(ptr, 243);

    Yes.

    Regards,
    -Dhruv.

          [ See http://www.gotw.ca/resources/clcm.htm for info about ]
          [ comp.lang.c++.moderated. First time posters: Do this! ]


  • Next message: max: "Re: easy question part 2"

    Relevant Pages

    • Re: How to Inherit a Keypress?
      ... I have some difficulty with the logic in the routine. ... MouseHookStruct pointed to by lParam. ... You might want to consider a construction similar to that ... wParam, lParam); ...
      (comp.lang.pascal.delphi.misc)
    • RE: I want to update a row if it exists and Insert if the row dont ex
      ... am creating application for construction of telecom sites. ... wanted update routine to check if the site exits else I ... > I am Using Left outer join to join the tables. ... The inner table may or may ...
      (microsoft.public.access.modulesdaovba)
    • ObjectConstruction Automatic Logs???
      ... I wrote a servicedComponent and set the constructionEnabledatribute ... constructroutine and started testing some errors. ... SQL Server does not exist or access denied. ... The following component is configured for Construction, ...
      (microsoft.public.dotnet.framework.component_services)