How to free the memory of evicted font faces when using cache system?

View: New views
2 Messages — Rating Filter:   Alert me  

How to free the memory of evicted font faces when using cache system?

by Crend King-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

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!

_______________________________________________
Freetype-devel mailing list
Freetype-devel@...
http://lists.nongnu.org/mailman/listinfo/freetype-devel

Re: How to free the memory of evicted font faces when using cache system?

by Werner LEMBERG :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

[Please don't write HTML emails to this list!  It greatly reduces your
chances to get a reply.]

Sorry for the late reply.

> 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_Face says "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?
It's really difficult to answer your question without seeing actual
code.  Please provide a small compilable code snippet (without
graphics output) which demonstrates your problems.

Note, however, that the cache subsystem is my weakest point; maybe I
can't answer your question at all in a satisfying way...


    Werner

_______________________________________________
Freetype-devel mailing list
Freetype-devel@...
http://lists.nongnu.org/mailman/listinfo/freetype-devel