[cairo] reference counting vs garbage collection

Jost Boekemeier jost2345 at yahoo.de
Tue Jan 4 04:10:40 PST 2005


On Mon, 2005-01-03 at 23:10, Owen Taylor wrote:

> You want a simple 'const char * filename' API for convenience. No memory
> management issues there. And then you need a more flexible "write
> another
> chunk of bytes" API. Something along the lines of:
> 
>  cairo_pdf_surface_set_output_func (cairo_surface_t       *surface,
>                                     cairo_write_func_t     func,
>                                     void *                 data,
>                                     cairo_destroy_notify_t destroy);


Yes.  Except that I would pass all necessary information in the
constructor instead of adding a separate set function:

cairo_output_file_t *cairo_output_file_create(name);
cairo_output_file_t *cairo_output_file_create(name, write_func, destroy_func, data);
cairo_ps_surface_create(output_file, ...)


> There is some argument that tying close() on a stream to destruction
> of that stream is wrong; 

Well, the only thing this saves is the malloc/free call for the file
structure.  Keeping objects makes more sense in OO languages when the
creation/destruction of the objects is expensive.


Jost




More information about the cairo mailing list