I have a dynamic array as a member of my class. I'm trying to find an efficient way to resize it and keep all of the information in it. I know that vectors would work well for this but I want to do this with a dynamic array instead.
My class has a dynamic array of type unsigned _int8 called data.
Is the following acceptable?
unsigned _int8 * temp = data;
data = new unsigned _int8[NewSize]();
if(OldSize >= NewSize)
{
for(int i = 0; i < NewSize; i++)
data[i] = temp[i];
}
else
{
for(int i = 0; i < OldSize; i++)
data[i] = temp[i];
}
delete [] temp;
Or should I do this a different way? Any suggestions?
Edit
Fixed an error in my example and changed char to unsigned _int8.
Edit 2
I will not be reallocating often, if at all. I want the functionality to be there to avoid having to write the code to create a new object and copy everything over if it's needed.
The class I am writing is for creating and saving Bitmap (.bmp) images. The array simply holds the file bytes. The image size will (should) be known when I create the object.