CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 14 of 14

Threaded View

  1. #11
    Join Date
    Jul 2002
    Posts
    107
    Hi Mike,

    (if indeed it was possible to call the destructor more than once considering that the "this" pointer would be invalid).
    The destructor is the first thing called when you delete, so the "free" would never be reached to invalidate the pointer.

    While I have no idea why this guy wishes to do this, there are reasons that you might wish do check something like this.

    I can think for several, but I'll give you a quick breakdown of one that popped in my head.
    you have a std::map.
    You have a dynamic list passed back from some obnoxious "windows" like api function which expects you to delete the memory it allocated...
    You have a bunch of static objects that you wish to sort and operate on with the returned dynamic ones.

    you put them in your map and run a loop to operate on them...
    you then have to run another loop and operate on those aswell...
    The performance is dropped by the second loop, especially if you need to a windows pump so it doesn't lock up your program. Cause both loops will need it if you have length operations or millions of elements...
    Then you need to delete the memory which is another loop which also requires a "anti-locking" mechinism if there a lots of elemets.

    if you approach the problem the same way this guy is, then you can delete each of the elements after you operate on them all in the same loop, so there is no need for the second or third loop.
    While you say "but the performance hit is minimal", sure it is, for only 1000, maybe 10000 but on 1000000? 100000000? you can save time by deleteing them as you go. And since the sorted list has pointers for both, you don't have to worry about whether it was a static or dynamic with this approach.

    Its not a hack, just a performance boost, it cuts a little un-necessary fat out of your program. If you make very intensive programs as I do, then you need to cut these chunks out so your program doesn't look like something MS made...

    However, I have no idea why he's doing it this way, such things may not be necessary for him and in someways may slow him down... hopefully he'll find another way.
    Last edited by oktronic; September 29th, 2003 at 07:48 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured