PDA

View Full Version : QVector, containers, deep copy



TheKedge
22nd January 2007, 13:26
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


void CLASS::getData(short* piData)
{
QVector<short> trace;
getData(&trace);
piData = trace.data();//do I need to copy this?

return;
}

wysota
22nd January 2007, 14:21
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.

Chicken Blood Machine
23rd January 2007, 05:45
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.