Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Going Native with FFI

Going Native with FFI

Slides of my Talk given at RubyConf Colombia 2019

Juan Carlos Ruiz González

September 20, 2019
Tweet

More Decks by Juan Carlos Ruiz González

Other Decks in Programming

Transcript

  1. ❏ Former software engineer @ MagmaLabs ❏ Remote work advocate

    ❏ RubyMe Q2 mentor ❏ I ❤ Open source @JuanCrg90
  2. @JuanCrg90 mkmf.rb is used by Ruby C extensions to generate

    a Makefile which will correctly compile and link the C extension to Ruby and a third-party library.
  3. Pros: - We can use C functions in our Ruby

    Code - We take advantage of the existing ruby.h library to create the extension Cons: - We need to add extra C code to create the bindings - This solution only works in MRI @JuanCrg90
  4. A foreign function interface (FFI) is a mechanism by which

    a program written in one programming language can call routines or make use of services written in another. @JuanCrg90
  5. Pros: - We don’t need to add additional C code

    - An FFI extension is multi-platform and multi-implementation Cons: - Complex macros are difficult to maintain - Same for callback functions @JuanCrg90