I have an application that is performing some processing on some images.
Given that I know the width/height/format etc. (I do), and thinking just about defining a buffer
In addition - to ensure a minimum of allocated memory:
void MyClass::OnImageReceived(unsigned char *pPixels, unsigned int uPixelCount)
{
m_pImageBuffer.swap(std::vector(
pPixels, pPixels + uPixelCount));
// ... process image etc. ...
}
vector::assign does not change the amount of memory allocated, if the capacity is bigger than the amount needed:
Effects: erase(begin(), end()); insert(begin(), first, last);