I have a structure containing some data, especially big statically allocated array. The array length is not always completely used.
I need to do very often a copy of this data (in a realtime loop), so I need it to be as efficient as possible. Therefore, I want to copy only the length of the array that contains useful data.
Following is my suggestion for an assignment operator override. Could you please elaborate on the efficiency of it, and compare with for example the copy-and-swap idiom that I do not quite understand (What is the copy-and-swap idiom?).
struct Config
{
// Assignment operator: Copy all data from other instance
Config& operator=(const Config&obj)
{
currentArrayLength = obj.currentArrayLength;
memcpy(array, obj.array, obj.currentArrayLength * sizeof(array[0]));
return *this;
}
/* Static */
static const size_t arrayLengthMax = 1000;
/* Data */
uint32_t currentArrayLength = 0;
int32_t array[arrayLengthMax];
}