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,218 of 33,346   
   Peter Liedermann to All   
   stl clear and erase.   
   29 Apr 12 13:09:22   
   
   From: peter09876@hispeed.ch   
      
   Hello,   
      
   The following resulted from a performance hotspot analysis in a larger   
   context.   
   Small vector  variables are built up (typical size 6) and   
   they are cleared by v.clear().  This happens millions of times.   
      
   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.  Could I be better off using old C arrays?   
      
   Any hint greatly appreciated, this is really a hotspot in my program.   
      
   Regards,   
   Peter   
      
      
   --   
         [ 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