freetype-devel
[Top][All Lists]
Advanced

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

RE: [Devel] FT_New_Memory()


From: Turner, David
Subject: RE: [Devel] FT_New_Memory()
Date: Wed, 13 Oct 2004 11:15:32 +0200

Hello,

> The documentation for freetype2 custom memory allocators reads:
> 
> Even with a default build, client applications are still able 
> to provide
> their own memory manager by not calling FT_Init_FreeType() 
> but follow these
> simple steps:
> 
>    1. Create a new FT_Memory object by hand. The definition 
> of FT_MemoryRec
> is located in the public file <freetype/ftsystem.h>.
> 
> (1) seems to be in error since FT_Done_FreeType() calls 
> FT_Done_Memory()
> which calls free() on the FT_Memory structure. It would appear that
> FT_New_Memory() needs to be propagated up from intertal/ftobj.h to an
> external interface.
> 
> Am I missing something obvious?
> 

Yes, you only need to allocate the FT_MemoryRec manager with its own
allocation routine. Do something like:

   MyAllocator  my_allocator = .... ;
   FT_Memory    my_memory    = (FT_Memory) my_alloc( my_allocator, 
sizeof(*my_memory) );

   my_memory->user    = my_allocator;
   my_memory->alloc   = my_ft_alloc;
   my_memory->realloc = my_ft_realloc;
   my_memory->free    = my_ft_free;

with

  static void*
  my_ft_alloc( FT_Memory  memory,
               long       size )
  {
    return my_alloc( (MyAllocator)memory->user, size );
  }

  static void*
  my_ft_realloc( FT_Memory  memory,
                 long       cur_size,
                 long       new_size,
                 void*      block )
  {
    return my_realloc( (MyAllocator)memory->user, block, new_size );
  }

  static void
  my_ft_free( FT_Memory  memory,
              void*      block )
  {
    my_free( (MyAllocator)memory->user, block );
  }              

And that's it.

I agree that the memory interface isn't very clever, but at least it works
at it is.

Hope this helps,

- David Turner
- The FreeType Project  (www.freetype.org)


> Thanks in advance,
> 
> Ken
> 
>  
> 
> _______________________________________________
> Devel mailing list
> address@hidden
> http://www.freetype.org/mailman/listinfo/devel
> 



reply via email to

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