什么时候应该使用 XS?
我正在写一篇关于 XS 的演讲,我需要知道社区何时认为适合使用 XS。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我正在写一篇关于 XS 的演讲,我需要知道社区何时认为适合使用 XS。
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(2)
我可以想到至少三个使用 XS 的原因:
Reason 1 中可用的东西是显而易见的,无需解释。
当你确实需要理由 2 时就不那么明显了。通常,您最好查看代码的结构。仅当您分析了您的代码 并有一个 基准 和 测试套件来证明 XS 代码更快且正确。
原因3是一个危险的原因。您实际上很少需要研究 Perl 的内部结构才能做某事,但至少有 一个有效案例。
I can think of at least three reasons to use XS:
Reason 1 is obvious and should need no explaination.
When you really need reason 2 is less obvious. Often you are better off looking at how the code is structured. You should only invoke reason 2 if you have profiled your code and have a benchmark and test suite to prove that the XS code is faster and correct.
Reason 3 is a dangerous reason. It is rare that you actually need to look into Perl's guts to do something, but there is at least one valid case.
在某些情况下,更好的内存管理是使用 XS 的另一个原因。例如,如果您有大量类似类型的对象,则可以通过 XS 更有效地管理。
KinoSearch
将其用于标记,例如,通过 XS 可以比作为一个巨大的标量池更有效地管理大字符串中的开始和结束偏移量。PDL
还有内存管理方面的内容以及速度。从长远来看,有人建议将这种方法的一部分集成到核心 Perl 中,最初是因为它提供了更好地共享线程数据的机会:请参阅:http://openparallel.com/2011/07/05/a-new-hope-for-efficient-safe-data-sharing- Between-threads-in-perl/。
In a few cases, better memory management is another reason for using XS. For example, if you have a very large block of objects of some similar type, this can be managed more efficiently through XS.
KinoSearch
uses this for tokens, for example, where start and end offsets in a large string can be managed more effectively through XS than as a huge pool of scalars.PDL
also has a memory management aspect to it, as well as speed.There are proposals to integrate some of this approach into core Perl in the long term, initially because it offers a chance to make sharing data in threading better: see: http://openparallel.com/2011/07/05/a-new-hope-for-efficient-safe-data-sharing-between-threads-in-perl/.