• Advertisement
Sign in to follow this  

External API Binding: to Wrap or not to Wrap?

This topic is 1043 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi,

 

I am working on binding external C APIs (such as openGL) to my angelscript engine, and I am wondering if it is wise to directly bind the functions of the external API or if I should write function wrappers instead.

 

I ask this question because these APIs typically have different calling conventions on different platforms (all win32 APIs are stdcall for example), so I am wondering if it may cause issues. For example, would it break pre-compiled bytecode sharing between platforms?

 

By the way does anyone know a good binding generator script for C APIs (I have seen a few C++ binding tools that seem to be mostly prototypes for the moment, but C APIs should be much simpler)? It would be great if it could handle typedefs and literals #DEFINE directives.... :-)

Share this post


Link to post
Share on other sites
Advertisement

The calling convention doesn't influence the pre-compiled bytecode. As long as the script function signature is the same the bytecode will be compatible.

 

To wrap or not to wrap mostly depends on your own preference, unless of course you're building the application for a platform that does not yet have support for native calling convention.

 

For application functions that are called with a very high frequency it may be beneficial to try both wrapped and native to see which performs best on that platform.

Share this post


Link to post
Share on other sites

Thanks! I was not quite sure about the calling convention and bytecode.

 

Wouldn't it be surprising that a wrapped function performs better? This probably only adds overhead because of the additional function call.

Share this post


Link to post
Share on other sites

The overhead of dynamically setting up the CPU registers that is necessary for calling the functions natively is quite similar to the overhead of the wrapper function. 

 

Take a look at what goes on in the CallSystemFunction and you'll get a feeling of the overhead. :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement