i'm trying to wrap opengl textures into an RAII based object but I don't know how to handle copying when a RAII object is very expensive to copy.
Here's an example of an expensive RAII object.
class Image {
public:
Image(const Image& other) {
this->pixels = other.pixels;
}
Image& operator=(const Image& rhs) {
this->pixels = rhs.pixels;
}
void push_pixel(uint8_t pixeldata) {
pixels.push_back(pixeldata);
}
private:
std::vector<uint8_t> pixels;
};
When the image object is copied from one to another e.g.
int main(int argc, char** argv) {
Image myimage;
Image newimage;
// Inserting 1 million pixels into the image.
for (uint32_t i = 0; i < 1000000; i++) {
myimage.push_pixel(0);
}
// Copying the image from myimage to newimage.
newimage = myimage;
return 0;
}
Results in an extremely expensive operation, are there are alternatives to this which has the same behaviour?
Thanks.