From: francis.glassborow@btinternet.com   
      
   On 30/04/2012 21:33, Chris Vine wrote:   
   > On Sun, 29 Apr 2012 16:38:19 -0700 (PDT)   
   > Daniel Krügler wrote:   
   >> Am 29.04.2012 22:09, schrieb Peter Liedermann:   
   >>> My free profiler "Very Sleepy", which has been of great use to me,   
   >>> points me to the following, which is not my code and therefore   
   >>> presumed to be STL-implementation. (VC++ 11, presumably Dinkum)   
   >>>   
   >>> void clear()   
   >>> 0.16s { // erase all   
   >>> 0.08s erase(begin(), end());   
   >>> 0.00s }   
   >>>   
   >>> Question: Why does it perform this erase as part of clear(), can I   
   >>> keep it from doing so and how? I see no point in erasing for a   
   >>> vector. As far as I remember what I have read, there   
   >>> should not be any erasing in this case. The (logical) length of the   
   >>> vector should be adjusted (constant complexity) and the old   
   >>> contents are left as garbage.   
   >>   
   >> The implementation you are observing, is conforming, because the   
   >> standard describes above semantics. Nonetheless you are right: A good   
   >> quality-implementation can skip the iteration here and can simply   
   >> adjust the internal length representation via an O(1) step. I'm   
   >> pretty sure that gcc 4.8 does this, for example, if the value type of   
   >> the vector has a trivial destructor.   
   >>   
   >>> Could I be better off using old C arrays?   
   >>>   
   >>> Any hint greatly appreciated, this is really a hotspot in my   
   >>> program.   
   >>   
   >> This is really an quality-of-implementation issue, you should ask your   
   >> vendor for improvements, bringing the hot-spot situation as an   
   >> example.   
   >   
   > Isn't this similar to the problem of constructing a vector of int of a   
   > particular size, which in C++98 requires the constructor to be called   
   > for each of the vector's elements (so initializing them to 0), whether   
   > that is wanted or not? I imagine C++11 requires the same.   
      
   Sorry but one of us is confused. ints do not have ctors so there is no   
   such requirement. In general the Standard does not specify how things   
   should be done only what the resulting behaviour should be.   
      
      
   --   
    [ 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)   
|