• Create Account

### #Actualrnlf

Posted 27 August 2012 - 12:40 AM

I don't think, a vector is the right tool for this job. I had exactly the same problem a few weeks ago and figured I could not rely on the compiler to optimize away the initialization of the vector elements with zeros, which would be actually a big performance hit, if this code was to run more than a few times per minute or so.

I recommend you use a std::unique_ptr (or boost::shared_ptr if you can't use C++11) to a manually created array like this:

std::unique_ptr<GLubyte[]> myBuffer(new GLubyte[size1*size2*3]);


This way, you get the benefits you would also get from a vector (which very much boils down to automatic cleanup) but you don't get the drawbacks (unneccessary initialization of the memory buffer. With a vector, you might end up doubling the time needed to read your pixels...

I know, using vector&co for everything is an advice you hear very often, but sometimes you have to know when to use something different.

### #1rnlf

Posted 27 August 2012 - 12:39 AM

I don't think, a vector is the right tool for this job. I had exactly the same problem a few weeks ago and figured I could not rely on the compiler to optimize away the initialization of the vector elements with zeros, which would be actually a big performance hit, if this code was to run more than a few times per minute or so.

I recommend you use a std::unique_ptr (or boost::shared_ptr if you can't use C++11) to a manually created array like this:

std::unique_ptr<GLubyte[]> myBuffer(new GLubyte[size1*size2*3]);