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 33,057 of 33,346   
   Andy Lutomirski to Ulrich Eckhardt   
   Re: Vector sizes and other missed optimi   
   17 May 13 15:36:37   
   
   From: luto@amacapital.net   
      
   On 05/17/2013 02:59 AM, Ulrich Eckhardt wrote:   
   > Am 16.05.2013 21:45, schrieb Andy Lutomirski:   
   >  > This has been annoying me for a while:   
   > [...]   
   >  > template   
   >  > void IncrementVec(Vec &v)   
   >  > {   
   >  >    for (size_t i = 0; i < v.size(); i++)   
   >  >      ++v[i];   
   >  > }   
   > [...]   
   >  > The code generation for f1 loads len_ on every iteration of the loop.   
   >   
   > I'd say the default for-loop should look like this:   
   >   
   >      for(size_t i=0, size=v.size(); i!=size; ++i)   
      
   Ugh.  This works, of course (although it now may result in a pointless   
   spill to the stack, depending on what's in the loop).  But I don't want   
   to make my users think about it.   
      
   My real usecase is for a multidimensional vector-like thing, in which   
   the class contains the strides as private member variables.  There isn't   
   a clean way to manually hoist the accesses out of loops.   
      
   More generally, any class that contains a pointer to the same scalar   
   type as one of its private members may be difficult for the compiler to   
   optimize well.   
      
   --Andy   
      
      
   --   
         [ 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