[cairo] text_to_glyphs and malloc/free
behdad at behdad.org
Thu Jun 5 16:28:55 PDT 2008
Currently the user-font text_to_glyphs callback is expected to malloc()
the glyph array. Cairo free()s it later. Is that acceptable?
Alternative would be once calling that function with no glyph array and
just get num_glyphs, then allocate the array and call the callback again
to fill it in. A more efficient alternative is to call it in with a
glyph array and its size, and let user bail out if the array is not
large enough. Anyway, both are cleaner on the malloc/free side, but
more pain for the user.
That's not all. Also have the other side of the problem. I will be
adding cairo_scaled_font_text_to_glyphs() soon. This time cairo needs
to allocate memory and user is responsible to free() it. Same approach
can be taken of course, that is, let user provide the allocated array
and size, and just return a larger size to signal not-enough-room.
So, which way?
"Those who would give up Essential Liberty to purchase a little
Temporary Safety, deserve neither Liberty nor Safety."
-- Benjamin Franklin, 1759
More information about the cairo