[Top][All Lists]

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

Re: [ft-devel] FT_Outline memory overallocation, or at least incorrect c

From: mpsuzuki
Subject: Re: [ft-devel] FT_Outline memory overallocation, or at least incorrect cache weighting?
Date: Fri, 5 Feb 2010 15:35:46 +0900

Dear Paul,

On Thu, 4 Feb 2010 15:29:28 -0800
Paul Messmer <address@hidden> wrote:
>The code above seems to believe there are n_points FT_Vectors allocated.
> However,
>.../base/ftoutln.c:  FT_Outline_New_Internal()
>    if ( FT_NEW_ARRAY( anoutline->points,   numPoints * 2L ) ||
>         FT_NEW_ARRAY( anoutline->tags,     numPoints      ) ||
>         FT_NEW_ARRAY( anoutline->contours, numContours    ) )
>      goto Fail;
>    anoutline->n_points    = (FT_UShort)numPoints;
>This seems to be allocating 2*n_points FT_Vectors, so there's a difference
>between how much memory is actually being used and how much it believes is
>being used.

Great thank you for finding the problem.

Tracking the history of the ftoutln.c, I think it came
from freetype-1 era (!). A "point" in TT_Outline was
described by TT_Vector, like this:

  struct  TT_Outline_
    TT_Short         n_contours;   /* number of contours in glyph   */
    TT_UShort        n_points;     /* number of points in the glyph */

    TT_Vector*       points;       /* the outline's points   */

But TT_New_Outline() allocated the buffer as the twice
of sizeof ( TT_F26Dot6 ), like this:

  TT_New_Outline( TT_UShort    numPoints,
                  TT_Short     numContours,
                  TT_Outline*  outline )

    if ( ALLOC( outline->points,   numPoints*2*sizeof ( TT_F26Dot6 ) ) ||
         ALLOC( outline->flags,    numPoints  *sizeof ( Byte )       ) ||
         ALLOC( outline->contours, numContours*sizeof ( UShort )     ) )
      goto Fail;

If it were written "sizeof ( FT_Vector )", this problem might not
have occured. This "2" was carried over to FreeType2, because the
initial version of FreeType2 still specified its size by twice of
sizeof( FT_Pos ), like this:

    if ( ALLOC_ARRAY( outline->points,   numPoints * 2L, FT_Pos    ) ||
         ALLOC_ARRAY( outline->flags,    numPoints,      FT_Byte   ) ||
         ALLOC_ARRAY( outline->contours, numContours,    FT_UShort ) )
      goto Fail;

Since freetype-2.1.0, FreeType2 uses FT_NEW_ARRAY() which
automatically calculate the size of array element with
sizeof( *first_arg ), so the factor 2 is not needed anymore,
as you've pointed out. So, this problem has long life since
freetype-2.1.0. The moment how overallocation can be found


I want to remove this extra factor "2". But you also mentioned
the possibility that the buffer over outline->n_points is used
in some special case, so I hesitate to remove it without careful
check. This over allocation is urgent issue for you? If not, I
want to work for this issue after next official release (expected soon).

Thank you again for detailed investigation and comment.


reply via email to

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