Hello,
I'm working on implementation of container class to hold
image data. What I want is to create a base class pixelContainer
which contains a pointer to pixel data and implements an iterator
to access it.
The memory managment of pixel data shall be
implemented in derived class as I want one derived class to
allocate the data dynamically and other one to use
memory on stack.
I also need to implement a copy constructor
in the base class which would dynamically allocate memory
and copy the pixel data.
Now the problem is how do I deallocate it?
a copy constructor...which would dynamically allocate memory
de-allocate in the destructor
base class -> allocate memory in constructor -> release same memory in base class destructor
child1 -> allocate different memory in constructor -> release same memory in child1 destructor
child2 -> use stack -> no worried here
That is so patronising I'm sure I misunderstood the question, could you elaborate? Maybe post some code?
The memory managment of pixel data shall be
implemented in derived class as I want one derived class to
allocate the data dynamically and other one to use
memory on stack.
This sounds like a lot of complication for premature optimization to me.
I also need to implement a copy constructor
in the base class which would dynamically allocate memory
and copy the pixel data.
So if you create an instance of the class that uses memory on the stack, and then copy a pixelContainer to it, then it now manages memory on the heap?
Simplify. Create a single pixelContainer class. Have it provide access to the pixels and manage the memory.