freetype-devel
[Top][All Lists]
Advanced

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

[ft-devel] How to free the memory of evicted font faces when using cache


From: Crend King
Subject: [ft-devel] How to free the memory of evicted font faces when using cache system?
Date: Mon, 12 Oct 2009 06:00:21 -0400

Hello. I have a question regarding the FreeType cache system. I do not know if I'm doing the right things with the cache. Please help me.


In my main function, I render text with different fonts. I extract the essential attributes of the current font to a structure, put it into a set (so that duplicate fonts will not be requested twice), and call FTC_Manager_LookupFace with face_id equals to the pointer of the structure. In the Font Requester function, I convert the face_id back to the structure, use it to load font file into memory, and construct FT_Face with FT_New_Memory_Face. In the function, the font file data is buffered in memory, and not freed when the function returns, because in the doc, the note under FT_New_Memory_Facesays "You must not deallocate the memory before calling FT_Done_Face.". Certainly I can record the buffer address in somewhere in my program, and could free them when the face is not needed anymore.


My question is, since the created faces are completely managed by the cache system, and there is no callback function to notify the eviction of a cached face, what is the appropriate time to free the font file data buffer? In my experiment, I set the max_faces of FTC_Manager_New() to 1, and render text with different fonts. The memory usage increases sharply.


I also searched the mailing list. In http://lists.nongnu.org/archive/html/freetype/2006-08/msg00000.html, Kristján asked about the similar question about node, not face, and David answered "first of all, nobody seemed to use this 'feature'". Does this answer also apply to the face case? And I found another implementation of using the cache system with FT_Stream (there is virtually nothing about these things in doc). If I change my "char *buf = new buf[file_len];" and FT_New_Memory_Face with FT_Stream and FT_Open_Face, will FT_Stream free the buffer automatically?


Please correct me if I'm doing something wrong. Thank you very much!

reply via email to

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