Roll our own qUtf8Printable()?
Thiago Macieira
thiago at macieira.org
Sun Feb 25 17:33:58 PST 2018
On domingo, 25 de fevereiro de 2018 14:34:28 PST Berthold Stoeger wrote:
> I think the compiler can't optimize the copy away, because QString doesn't
> copy the string, but does reference counting. I'm not sure if it is allowed
> to throw away the side effects of the ref()/deref() calls? This does some
> atomic stuff, so is obviously a bit hairy.
I'm not sure it can. Because the variable is an atomic, the compiler may
conclude it cannot remove a pair of operations that reverse each other,
because another thread may find the modified value in-between. That's true
even for relaxed memory access, which ref counts are not.
> [Sidenote: There's a reason the C++-standard disallows reference counting
> for its string class.]
There is, but this isn't it. The concern is the unexpected memory allocation
when calling a non-const function. The standard banned reference counting by
requiring a few of those functions to have constant time (O(1)) operation,
which can't be implemented if you need to allocate memory and memcpy.
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Software Architect - Intel Open Source Technology Center
More information about the subsurface
mailing list