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,159 of 33,346   
   woodbrian77@googlemail.com to All   
   Re: byte buffer implementation   
   03 Aug 13 23:13:24   
   
   On Saturday, August 3, 2013 2:50:02 AM UTC-5, fmatthew5876 wrote:   
   >   
   > In practice the signed vs unsigned char issue hardly matters   
   > unless you're treating the chars themselves as 8 bit ints.   
      
   This is the impression I've had also.   
      
   >   
   >   
   > I have no qualms with C style arrays especially for a temporary buffer   
   > for doing IO. There's nothing faster than allocating a fixed buffer   
   > on the stack.   
   >   
   > std::array is just like a struct containing a C array   
   > except that it always initializes its members. This is a slight   
   > but not really problematic inefficiency if you're just   
   > about to write to the buffer.   
   >   
      
   I don't think std::array initializes its members:   
      
   #include    
   #include    
   #include    
      
   int main()   
   {   
     int oldschool[200];   
     std::array a;   
     std::vector v(200);   
      
     std::cout << "oldschool[134] = " << oldschool[134] << std::endl;   
     std::cout << "a[134] = " << a[134] << std::endl;   
     std::cout << "v[134] = " << v[134] << std::endl;   
     return 1;   
   }   
      
   oldschool[134] = -887447128   
   a[134] = -41345424   
   v[134] = 0   
      
      
   >   
   > You can use a unique_ptr with operator new [] to have a heap allocated   
   > fixed size array. Use unique_ptr, not a raw pointer so that it is cleaned up   
   > automatically.   
   >   
   > std::vector is flexibly growing array that you can append and   
   > insert into forever. If you need this append behavior then use a vector.   
   > If you don't then use one of the other options.   
   >   
      
   I have a place where I'm thinking about switching from vector   
   to array, but am not sure about heap/stack potential problems.   
   The buffers could be large - over a megabyte.   
      
   Brian   
   Ebenezer Enterprises   
   http://webEbenezer.net   
      
      
   --   
         [ 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