[cairo] Re: Re: Re: cairo c++ bindings

Mike Hearn mike at plan99.net
Fri Nov 25 07:20:20 PST 2005


On Fri, 25 Nov 2005 15:22:42 +0100, Murray Cumming wrote:
> The function is probalby just returning an integer. And we would just if()
> the result. Is that likely to be significant?

I'm not sure. For an immediate mode API like Cairo I suspect it could be.
OpenGL implementations usually optimize the function call overhead a lot:
for instance with vertex arrays, with optimized TLS implementations and so
on. 

When you're doing animation, and you want to throw a bazillion
function calls per second through a library, cycle-level
optimization becomes interesting.

As to the result of a function call and an if statement: it might be
significant. It means a pipeline-stalling comparison for every function
call. Also, on some platforms like MacOS X cross-library calls are very
slow.

> That would make it difficult to throw exceptions through the C callback.

Maybe ... C libraries can have exceptions thrown across them if they're
built with that in mind. I guess most of the error paths in Cairo look
like:

  if (error_condition) 
  {
      cairo->status = ....;
      return;
  }

So I guess it boils down to a cost:benefit analysis  -  how much overhead
does checking every call entail vs how hard is it to make Cairo exception
safe?

An alternative is to do what things like the Java OpenGL bindings do, and
have a special debug mode where every call is checked and can throw, and a
release mode where call results are never checked.

thanks -mike



More information about the cairo mailing list