QVector, containers, deep copy
Hi,
I've got an wrapper/overload func below. My question: after calling this function, is my data valid? Is a deep copy done?
How should I do it best? Should I 'new' a QVector or should I ::memcpy()?
thanks
K
Code:
void CLASS::getData(short* piData)
{
QVector<short> trace;
getData(&trace);
piData = trace.data();//do I need to copy this?
return;
}
Re: QVector, containers, deep copy
Quote:
The pointer remains valid as long as the vector isn't reallocated.
You get a pointer to the actual data, no copy is being done. If you really need a pointer (do you?) then you should make a copy. But I don't see any reason for a need for a persistent pointer other than using some legacy pointer based API.
Re: QVector, containers, deep copy
Quote:
Code:
void CLASS::getData(short* piData)
{
QVector<short> trace;
getData(&trace);
piData = trace.data();//do I need to copy this?
return;
}
In addition to what Wysota said, piData needs to be a short** or a short&*, or that method is not going to do very much.