FFI (语言交互接口(Foreign Function Interface))
FFI(Foreign Function Interface)是用來與其它語言交互的接口,
在有些語言里面稱為語言綁定(language bindings),
Java 里面一般稱為 JNI(Java Native Interface) 或 JNA(Java Native Access)。
由于現(xiàn)實(shí)中很多程序是由不同編程語言寫的,必然會(huì)涉及到跨語言調(diào)用,比如 A 語言寫的函數(shù)如果想在 B 語言里面調(diào)用,這時(shí)一般有兩種解決方案:一種是將函數(shù)做成一個(gè)服務(wù),通過進(jìn)程間通信(IPC)或網(wǎng)絡(luò)協(xié)議通信(RPC,RESTful等);另一種就是直接通過 FFI 調(diào)用。前者需要至少兩個(gè)獨(dú)立的進(jìn)程才能實(shí)現(xiàn),而后者直接將其它語言的接口內(nèi)嵌到本語言中,所以調(diào)用效率比前者高。
http://www.voidcn.com/article/p-uyomozse-bnw.html
Compilers for high level languages generate code that follow certain conventions. These conventions are necessary, in part, for separate compilation to work. One such convention is the "calling convention". The "calling convention" is essentially a set of assumptions made by the compiler about where function arguments will be found on entry to a function. A "calling convention" also specifies where the return value for a function is found.
Some programs may not know at the time of compilation what arguments are to be passed to a function. For instance, an interpreter may be told at run-time about the number and types of arguments used to call a given function. Libffi can be used in such programs to provide a bridge from the interpreter program to compiled code.
The libffi library provides a portable, high level programming interface to various calling conventions. This allows a programmer to call any function specified by a call interface description at run time.
FFI stands for Foreign Function Interface. A foreign function interface is the popular name for the interface that allows code written in one language to call code written in another language. The libffi library really only provides the lowest, machine dependent layer of a fully featured foreign function interface. A layer must exist above libffi that handles type conversions for values passed between the two languages.
https://github.com/libffi/libffi
總結(jié)
以上是生活随笔為你收集整理的FFI (语言交互接口(Foreign Function Interface))的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 常见注入手法第二讲,APC注入
- 下一篇: 如何优化个人博客的访问速度