[Development] Why can't QString use UTF-8 internally?

Marc Mutz marc.mutz at kdab.com
Wed Feb 11 00:40:28 CET 2015


On Tuesday 10 February 2015 22:26:50 Thiago Macieira wrote:
> It's not insurmountable. I can think of two solutions:
>  1) pre-allocate enough space for the UTF-16 data (strlen(utf8) * 2), so
> that  the const functions can implicitly write to the UTF-16 block when
> needed. Since the original UTF-8 data is constant and if there are no
> out-of-thin-air values, multiple threads could do this operation
> simultaneously safely.

No, they can't. The writes conflict and neither happens-before the other -> 
data race -> UB.

Your #2 is sound, of course, as long as readers loadAcquire the utf16 data 
pointer.

-- 
Marc Mutz <marc.mutz at kdab.com> | Senior Software Engineer
KDAB (Deutschland) GmbH & Co.KG, a KDAB Group Company
www.kdab.com || Germany +49-30-521325470 || Sweden (HQ) +46-563-540090
KDAB - Qt Experts - Platform-Independent Software Solutions



More information about the Development mailing list