kdb+ FFI

Kdb+ FFI: Access external libraries more easily from q

22 Nov 2017 | ,
Share on:

By Fintan Quill

Following on from the hugely popular Python library and interface embedPy and PyQ, Kx has released an FFI as part of the Fusion for kdb+ interfaces. As with embedPy and PyQ, this FFI is open-sourced under the Apache 2 license.

The kdb+ FFI is a foreign function interface library for loading and calling dynamic libraries from q code. It has been adapted and expanded upon from a library originally written by Alex Belopolsky of Enlightenment Research. With the kdb+ FFI you can now call your favorite C/C++ libraries directly from q without the overhead of having to compile shared objects and load into q using the 2: command.

In order to use the kdb+ FFI, you need to install kdb+ version 3.4 or later as well as libffi3.1+. Instructions are available for installing libffi using your package manager of choice such as apt-get or brew. The kdb+ FFI package then needs to be downloaded and unpacked. Once unpacked, simply load the ffi.q script into your q process and you’re done!

There are two main functions of note within the interface, .ffi.cf to do a once-off call to a function and .ffi.bind binds a C call to a q function for multiple calls.

What are the advantages of using the kdb+ FFI? Users no longer have to write their own C/C++ code or use compiler toolchains to connect to many common libraries. A second advantage is when interacting with the operating system the kdb+ FFI doesn’t carry the overhead of forking an extra process similar to the system command in q.

Within the project are several examples including:

  • PCRE bindings for regular expressions
  • BLAS bindings for common linear algebra operations
  • Rmath bindings for random number generators and probability functions
  • Callback registration

You can check out the project on the Kx Systems’ Github where you can also send feedback and add to the project.

Happy coding!

Fintan Quill is Global Head of Sales Engineering for Kx and is based in New York City.

SUGGESTED ARTICLES

cryptocurrency microstructure with kdb+

Combining high-frequency cryptocurrency venue data using kdb+

19 Sep 2018 | , , , ,

By Eduard Silantyev   Eduard Silantyev is an electronic trading systems developer and a cryptocurrency market microstructure specialist based in London. Follow Eduard on LinkedIn or Medium to read more of his blogs about cryptocurrencies. The original title of this blog is “Cryptocurrency Market Microstructure Data Collection Using CryptoFeed, Arctic, kdb+ and AWS EC2 | Handling […]

Signal processing in kdb+

Signal processing with kdb+

6 Sep 2018 | , ,

In the latest in our ongoing series of kdb+ technical white papers published on the Kx Developer’s site, Kx engineer Callum Biggs examines how kdb+/q can be used instead of popular software-based signal processing solutions. Signal processing is used for analyzing observable events, such as IoT sensor data, sounds, images and other types of pulses […]

Python vs kdb+ for data analytics

A comparison of Python and q for data analysis

21 Aug 2018 | , , , ,

Guest blogger Ferenc Bodon illustrates using Python, SQL and kdb+ for data analytics in this blog. He takes an example that goes just one step beyond the simplest use cases by performing some aggregation based on multiple columns. Anybody who analyzes data tables will bump into this type of problem, probably on the third day.