home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.c++.moderated      Moderated discussion of C++ superhackery      33,346 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 31,744 of 33,346   
   Miles Bader to Martin B.   
   Re: Cost of deleting a null pointer   
   17 Dec 11 01:39:01   
   
   From: miles@gnu.org   
      
   "Martin B." <0xCDCDCDCD@gmx.at> writes:   
   >>> Is this just a Quality of Implementation issue, or is it reasonable to   
   >>> expect that deleting a null pointer should be expensive?   
   >>   
   >> (...)  so I went snooping around for   
   >> opportunities to optimize. To my surprise, the compiler was not   
   >> checking to see if the argument of delete() was 0 before invoking the   
   >> machinery that effects delete().   
      
   Of course, even if it's not testing-for-zero around the call to   
   operator-delete, it's pretty likely that operator-delete looks   
   something like:   
      
      void ::operator delete(void *ptr, ...)   
      {   
         if (ptr)   
           { /* really do it */ }   
      }   
      
   and on a modern processor, the cost of the function call shouldn't be   
   horribly much... 30x seems ... surprising...   
      
   [In general, I'd expect delete of NULL pointers to be relatively rare,   
   so it seems to make good sense to optimize for the common case by   
   putting the test in the function, rather than around the call.]   
      
   -Miles   
      
   --   
   Quotation, n. The act of repeating erroneously the words of   
   another. The words erroneously repeated.   
      
      
         [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
         [ comp.lang.c++.moderated.    First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca