[Fontconfig] Lifetime of strings from FcPatternGetString
keithp at keithp.com
Tue Jul 8 17:24:21 PDT 2008
On Tue, 2008-07-08 at 15:37 -0700, Sairus Patel wrote:
> Hello all,
> It’s not clear from the FC documentation how long we can expect a
> string returned from a pattern by FcPatternGetString to remain valid.
You shouldn't count on them being valid any longer than the pattern is
> The doc does say that FcPatternGetString provides a pointer to the
> actual string within the pattern, but as in the code snippet below,
> the pattern is destroyed but I've observed that the returned filename
> value seems to remain usable.
The strings will have varying lifetimes depending on what kind of
pattern you're using.
Patterns from font files are live as long as that directory cache is
mapped, which is generally the same as the application lifetime unless
the directory is rescanned. Of course, any patterns in use by the
application will hold the whole directory content from being freed.
Patterns created by the user will end up with strings that are dumped
into a shared data structure, and so they have lifetime equal to the
> Am I purely lucky that the memory is still valid, or are these strings
> “atoms” i.e. strings that remain valid for the entire lifetime of
> FontConfig? Is this documented anywhere?
Most of the time, the strings will persist, but strings in patterns
loaded from disk can go away when the pattern is freed. "don't do that".
Note that these patterns are entirely shared, so it's almost free
(again, except when the directory is rescanned) to hold a reference to
the pattern if you need to store the string somewhere.
keith.packard at intel.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://lists.freedesktop.org/archives/fontconfig/attachments/20080708/25a12b70/attachment.pgp
More information about the Fontconfig