Perl XS 和内联::C

发布于 2024-11-26 19:43:51 字数 136 浏览 0 评论 0原文

使用 XS 和 Inline::C 模块有什么区别?有人在这个问题中提到了这一点,这让我很好奇。

What's the difference between using XS and the Inline::C module? This was mentioned by someone in this question and has made me curious.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

过期情话 2024-12-03 19:43:51

Inline::C 生成 XS 并构建生成的模块。它在运行时执行此操作,尽管它会缓存过去的构建。

Inline::C 可能更容易使用,但也有一些缺点。第一次运行时,它会减慢启动速度,需要在运行时创建文件的权限,并且需要工具来编译模块。此外,它使系统管理员更难安装。

好处是,一旦事情开始成形,您就可以获取生成的 XS 并消除 Inline::C。这使得它对于原型设计非常有用。

Inline::C generates XS and builds the generated module. It does this at run-time, although it caches past builds.

Inline::C is possibly easier to use, but there are a few downsides. The first time it runs, it slows down startup, it requires permissions to create files at run-time, and it requires the tools to compile the module. Furthermore, it makes it harder for a sysadmin to install.

The upside is that you can grab the generated XS and eliminate Inline::C once things start shaping up. This makes it useful for prototyping.

蒲公英的约定 2024-12-03 19:43:51

内联在编译 Perl 的同时编译 C 代码,并且每次更改源代码时都会重新编译。 XS 编译一次,二进制文件像库一样保存为 .so 文件。

Perl 是用 C 编写的,因此 XS 使用本机 Perl 类型和子例程机制。使用 XS 的模块的运行效率几乎与内置语言功能一样高。在 Inline 中做一些事情比较困难,并且在调用或从代码返回时会有一个转换步骤。话虽这么说,内联在不需要时不重新编译方面做得很好,并且内联代码的转换不太可能对性能造成明显的影响。

最后,编写 XS 假设您正在打包一个模块。需要大量 Perl 内部和模块打包的设置和知识。如果您只需要从 Perl 调用 C 库,那么最好使用内联。

Inline compiles the C code at the same time when your Perl is compiled, and will be recompiled every time your source code is changed. XS is compiled once and the binary is saved as a .so file like a library.

Perl is written in C so XS uses the native Perl types and subroutine mechanisms. A module using XS runs almost as efficiently as a built-in language feature. It's more difficult to do some things in Inline, and there will be a conversion step when calling or returning from your code. That being said, Inline does a good job of not recompiling when not necessary, and the conversions into and out of Inline code aren't likely to be a noticeable performance hit.

Finally, writing XS assumes that you are packaging a module. There is a lot of setup and knowledge of Perl guts and module packaging required. If you just need to call a C library from Perl, you are better off using Inline.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文