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 32,979 of 33,346   
   Francis Glassborow to Balog Pal   
   Re: Sequence container capacity after ca   
   07 Apr 13 05:40:56   
   
   From: francis.glassborow@btinternet.com   
      
   On 07/04/2013 04:32, Balog Pal wrote:   
      
   > With that clarification do you still see a problem?   
      
   With that clarification I do not understand what you are trying to   
   fix.  Consider this code fragment:   
      
   atype * at = new atype;   
   delete at;   
      
   The compiler treats this as   
      
   get enough memory for an instance of atype   
   construct a default instance of atype in that memory   
   store the location of the object in at.   
      
   Destroy the object of type atype found at the given location   
   release the memory obtained for the creation of an atype instance   
      
      
   Now, IIUC, you simply want a licence to somehow remove the memory   
   allocation/deallocation. How would you manage that? The instance has   
   to reside somewhere.   
      
   Please note that the standard does not mandate how the memory is   
   obtained so the default operator new and operator delete can work any   
   way that the implementer chooses. The implementation is entirely free   
   to use stack based memory if it can determine that the lifetime of the   
   instance will be entirely contained within the time that the stack   
   memory is valid. Note that this is only normally the case when the new   
   and delete expressions are in the same (brace limited) block.   
      
   Now, note that programmers use dynamic objects for several purposes   
   (for example, large objects that they do not want to reside on the   
   stack - a limited resource on some platforms).  I cannot imagine   
   (maybe a failure of my imagination) a case where a competent   
   programmer would want a compiler to start overruling a decision to use   
   dynamic memory unless it can determine that doing so will have no   
   side-effects (note that performance is not a side-effect even though   
   you may be able to determine that an optimisation has been applied   
   because of the execution time of the code -- that is a serious problem   
   to some benchmark programs)   
      
   So my answer is that from what I currently understand I do not see any   
   need to broaden the already existing licence for optimisation as   
   regards dynamic objects.   
      
   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