Handling resource pointer with RAII

Started by
9 comments, last by Khatharr 7 years, 4 months ago

Another question how would I still use RAII in this principle as I almost certainly will need to create a runtime bitmap. I have a sprite loader which takes a large bitmap and spits out small ones that have one cell per bitmap, so I need to allocate data and init the headers, is there a safe way of doing this?


This seems like a clear sign that your BitmapFile class is doing too much. Bitmaps don't always come from files and the two concepts should be handled separately. If I were designing this feature, I'd make a Bitmap class that stores a chunk of pixels and has operations to draw those pixels on screen, and another class that knows how to read files and extract the bitmaps they contain. That way you could create bitmaps from other sources without being tied to files or file formats.


Uh...

So loading the resource is not the responsibility of the resource class, but rendering it is? Seems a bit silly.

The accessors for header data are the part that worries me.

Also, @Snake, RAII for a dynamic array is std::vector.

Oh, and...

BitmapFile& operator=(const BitmapFile& rhv) = delete; //prohibit copying of this RAII object


BitmapFile(const BitmapFile&) = delete; //also disable copy construction
BitmapFile(BitmapFile&& rhs) = default; //and enable move construction - default will work with vector but not UCHAR*
void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

This topic is closed to new replies.

Advertisement