Changing bytestream (unsigned char*) to vector

I want to change:
unsigned char* lpPixelArray
to
std::vector<unsigned char> vPixelArray

I allocate memory for the lpPixelArray by:
lpPixelArray = (unsigned char*)malloc(cxLength * 3 * cyLength);

However when I instantiate the object using my overridden constructor I do know the size I need the array to be: So could I check then instantiate the vector to the correct size at this point?
1
2
3
SingleMonitorInfo(const MONITORINFOEXW& rfMONITORINFOEX) : 
...
(vPixelArray ? {(cxLength * 3 * cyLength), 0} : {})


N.B/ I intend on making in it's own class MultipleMonitorInfo
vector<SingleMonitorInfo>
With this I will create two lists, an old list and a new list. If old SingleMonitorInfo equals new: copy the vPixelArray, then delete the old SingleMonitorInfo. I am not sure how this relates to copy constructors, equals operators and smart pointers.

I am not sure what to do in this case with how I re-design my class.
I'm confused. Can you try to rewrite what you're trying to say in a more understandable manner?

You can re-size the vector at any point by using vPixelArray.resize();, if that's what you're looking for.
Current problem:

Whether to instantiate the size or use resize where I previously used malloc?

If on instantiation (As the size shouldn't change after creation) should I run any validation?

Thinking of the future and how it relates to a future class:

Do I create an over-ride comparison* operator? Which checks (the name and resolution) one monitor against another? As I believe these two are the only essential variables needed.As if position changes but resolution is the same, it might not affect vPixelArray. The name refers to the szDeviceName of MONITORINFOEX structure.

If I create two instances of vector<SingleMonitorInfo>, which contains the list of all monitors, I am worried about how this might affect:

Scope of the vPixelArray (Should I use smart pointers here? Maybe an estimated size?)

I hope I have provided enough information and it is a bit clearer what I am asking. I have been reading a lot and it just gets more confused as to where to start, and implementation.

Edit: Does vPixelArray:
Count as a resource?
Need a custom copy constructor and, Big Rule of Three, Five, Zero implementation?
Last edited on
Topic archived. No new replies allowed.