[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [ft-devel] does the face cache really work ?

From: Turner, David
Subject: RE: [ft-devel] does the face cache really work ?
Date: Wed, 1 Jun 2005 14:09:03 +0200

Hello Anstinus,

> But the face_id is just a pointer, then if I write the 
> following code, it 
> will not work as I expect:
> [code removed]
> The ftFace1 and ftFace2 will have the same value!
An important design point of the cache subsystem is that a
FTC_FaceID value (i.e. the address contained by the pointer)
is used to _uniquely_ identify a given cacheable face.

This is essential to perform fast lookups (a pointer comparison
is so much faster than calling a callback that may itself call

I guess we should update the documentation to reflect this

> If I use malloc() to create My_FaceID_Rec, the face_id in 
> each node will have different values, that is to say, each time I lookup a 
> face, the cache will create a new node for me!.
Not each time. The cache holds a list of opened FT_Face objects,
in most-recently-used order, whose size is bounded by the value
of the 'max_faces' parameter you used when calling FTC_Manager_New
(the default being 2 faces max).

When you call FTC_Manager_LookupFace, the manager first looks for an
opened FT_Face in the list which corresponds to the FTC_FaceID value.

- If it is found, it is returned (and moved to the head of the list).

- If it is not found, it tries to create a new one, then adds it to
  the list before returning it.

- When the list if full, the oldest one is automatically discarded,
  which is why you shouldn't rely on the FT_Face being present once
  you've called another cache function.
Same thing with the FT_Size objects retrieved with FTC_Manager_LookupSize
(except that this operation also performs a face lookup).

> The situation is that each My_FaceID_Rec object is associated 
> with a face in cache. Then if I want to make the face cache run properly, I 
> have to cache the My_FaceID_Rec objects at first!

You don't need to cache your My_FaceID_Rec objects. Just build a list
of them, corresponding to the list of available faces you have, and
that's all. The lifecycle of FT_Face objects is handled automatically
by the cache sub-system.

Note that you should normally never change the content of the data
pointed to by a FTC_FaceID. If you really need to do it (e.g. if you
'unload' a font), call FTC_Manager_RemoveFaceID to indicate that
all nodes, FT_Face and FT_Size objects corresponding to a given
face_id should be discarded.

Hope this helps,

- David Turner
- The FreeType Project  (

reply via email to

[Prev in Thread] Current Thread [Next in Thread]