Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>While FFI makes it easy to call native code, you really shouldn't use it to for something you have to do often, like calling a database library. From the docs:</p> <blockquote> <p>There is non-trivial overhead associated with FFI calls. Comparing a hard-coded binding version of strtoul() to an FFI version of strtoul() shows that the native hard-coded binding is orders of magnitude faster. So don't just use the C version of a function just because it's faster. There's a significant cost in FFI calls, so make them worth it.</p> </blockquote> <p>In other words, FFI works, but is <em>slow</em>. This is fine if you just need to make a few calls, but very bad news if you need to make frequent calls.</p> <p>What you need to do is write an <a href="http://nodejs.org/api/addons.html" rel="nofollow noreferrer">addon</a>. Addons are C++ modules that provide glue to C and C++ libraries. (Just because you must write the addon in C++ doesn't mean you can't call pure C code from the addon!)</p> <p>The node <a href="http://nodejs.org/api/addons.html" rel="nofollow noreferrer">docs</a> provide plenty of examples that should get you started. If you're working with Windows, <a href="https://stackoverflow.com/a/9625030/201952">here's some tips</a> to get VS set up.</p> <p>If the calls to the C library are blocking, you'll need to make them async. <a href="http://nikhilm.github.com/uvbook/threads.html#libuv-work-queue" rel="nofollow noreferrer">libuv provides a thread pool you can do the work on.</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload