[Development] ODP: RFC: Deprecating setSharable / isSharable in our containers and QString
Thiago Macieira
thiago.macieira at intel.com
Thu Feb 20 18:01:18 CET 2014
Em qui 20 fev 2014, às 12:14:24, Nowacki Jedrzej escreveu:
> H,
>
> One hand raised.
>
> The original use case is buried in the Qt history, when I was asking /
> digging why we had that, I found that in some really rare and obscure cases
> it may be useful. For example when you want to control the life time of a
> data in your container. Imagine QVector::fromRawData which doesn't copy the
> data but just update d, the internal header:
>
> char t* = strdup(...);
> {
> QVector<char> tmp = QVector<char>::fromRawData(t);
> tmp.setSharable(false);
> Qt.Api.call(tmp);
> }
> free(t);
>
> In my opinion we can safely deprecate it.
The problem with that is that it might cause extra memory allocations when
something accidentally copies it in your called function. And you also wrote a
nice example that calls a function, instead of trying to return it (which
would trigger a deep copy).
In any case, you may remember from the pre-5.0 discussion that I want to
introduce an "external data" type of handler. So the above would be:
char *t = strdup(...);
QVector<char> tmp = QVector<char>::fromRawData(t, strlen(t), free);
Qt.Api.call(tmp);
When all copies go out of scope, QVector calls free(data()).
--
Thiago Macieira - thiago.macieira (AT) intel.com
Software Architect - Intel Open Source Technology Center
More information about the Development
mailing list