I have a class Foo
that has defined a public struct Data
inside of it, with a QVector<Data> allData
nesting multiple objects of the Data
struct inside of it:
class Foo
{
public:
struct Data {
uchar valueA;
uchar valueB;
uchar valueC;
};
private:
QVector<Data> allData;
};
I also have two other classes B and C that need to read allData
multiple times a second. They shall not be able to write into allData
at all, this shall be handled by the Foo
class only.
With performance in mind, I'm looking for a way to do this without creating a new QVector everytime. As far as I understand, a method like this:
QVector<Data> getAllData() {
return allData;
}
would result in a new object being created everytime this method gets called.
If I gave the other classes something like a QVector<Data> allDataCopy
that is just being handed over to Foo
to be filled with the values inside of allData
that would just result in having to copy all values everytime, which I imagine would not be very perfomant aswell.
Is there any efficient way to solve this?