Lifetime of QByteArray references when constructing QRawFont using loadFromData()
-
Does Qt make any guarantees about the use and copying of QByteArray objects passed to QRawFont::loadFromData(), and how does this apply to a QByteArray that doesn't own the memory it points to (constructed via QByteArray::fromRawData)?
I am working on an application that loads the font bytes in another language and gives a pointer to it to Qt across the FFI boundary to avoid making full copy of the font data. I need to know if Qt will attempt to access that memory even after the QRawFont object has been freed, and I couldn't find anything in the documentation about it.
Will destroying the QRawFont object be enough to ensure that the underlying memory is safe to be freed?
-
You should not pass any object anywhere with a shorter lifetime than where you pass the object too except it is stated otherwise. Therefore make sure the data referenced by QByteArray::fromRawDate() outlifes the QFontEngine or don't use fromRawDate() here.
-
How long does a QFontEngine live for, and if it lives longer than the QRawFont, can I remove fonts from it? I want to make sure that when a font is no longer needed, I can safely free the data that the QByteArray references, so that I don't keep an unused font in memory.
-
If you delete the font the underlying engine is also deleted. But why bother with these few bytes you might save when using fromRawData. It's not worth the trouble.
-
If the font engine is destroyed when the QRawFont is, and the font engine isn't shared between different fonts, then it should be fine.
And unfortunately for me, I don't know what fonts or how many fonts might be loaded, so I want to prevent two copies of the font data existing at once.Thanks for the help though!
-
P PolarFox has marked this topic as solved