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 32,976 of 33,346    |
|    Francis Glassborow to Balog Pal    |
|    Re: Sequence container capacity after ca    |
|    06 Apr 13 06:15:27    |
   
   From: francis.glassborow@btinternet.com   
      
   On 05/04/2013 06:46, Balog Pal wrote:   
   > On 4/4/2013 6:02 AM, Francis Glassborow wrote:   
   >> On 03/04/2013 18:28, Öö Tiib wrote:   
   >>   
   >>> I am not certain if needless memory management may be optimized   
   >>> out, but I suspect that no. At least I haven't seen any C++   
   >>> compilers attempting to optimize that:   
   >>>   
   >>> int main(){delete new char;}   
   >>>   
   >>> Everywhere it calls operator new and operator delete on whatever   
   >>> optimization level despite to human eye it looks pointless to call   
   >>> those. That means that dynamic memory management operations are   
   >>> somehow considered externally observable behavior and so doing it   
   >>> needlessly is doubly bad.   
   >>   
   >> It is quite hard to optimise these calls away because the new   
   >> expression involves a call to operator new which may have been   
   >> replaced by one that has some extra (observable) functionality. The   
   >> same is true for the delete expression.   
   >   
   > Hmm, an excellent point. And smells like a defect to the standard or   
   > at least a good opportunity for improvement.   
   >   
   > To me that case is the same as copy-elision.   
      
      
   Copy elision is a very special case because a copy ctor carries out a   
   conceptual process that has no side effects (the concept of copying   
   that is). C++ therefore issues a licence to elide copying even when   
   the actual ctor generates a side-effect and thereby warns the   
   programmer that they cannot in general rely on such a side-effect   
   occurring (though if you need it, there are ways to ensure that an   
   actual copy will be produced)   
      
   There is nothing in the concept of creating and destroying a dynamic   
   object that suggests there will not a be a side-effect (observable   
   behaviour) so the compiler optimiser has to fall back on the general   
   licence to remove code whose actions cannot result in a side-effect.   
      
   Note that in general a new-expression executes both a new operator   
   (that might be user provided) and a ctor. A delete expression   
   similarly executes both a delete operator and a dtor. Do we really   
   want to tell programmers that the optimiser is free to remove their   
   new/delete pair even when the execution of such a pair will produce   
   observable behaviour? IMO we do not (even the licence to elide copy   
   construction has been questioned in the past though I think most   
   programmers now think it justified in the contexts where it is   
   permitted).   
      
   Francis   
      
      
   --   
    [ 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