本文介绍了Erlang:与Xalan接口:端口驱动程序或nif?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个真正的XSLT处理器与erlang合作。哪个是最好的界面,nif或端口驱动?根据nif文档,nif调用阻塞运行时间,所以不要花太多时间。正在处理一个长xml文件太长?



另外,我想允许在转换过程中的erlang回调。这似乎有可能吗?可能与nif但不是端口驱动程序,反之亦然?



我从来没有写任何C,所以我认为这将是很好的介绍。 Xalan是C ++。我假设nif可以使用,对吗?

解决方案

我建议建立一个端口驱动程序。



NIF工具是为语言
添加新的内置函数的一种方法,并加快在纯Erlang中实现的速度太慢的事情。
NIF被认为是实验性的,所以在以后的版本中,界面可能会
大幅改变。



编写端口驱动程序意味着实现
a C (或C ++)共享库,其行为像整个erlang 进程
这允许更大的灵活性,因为您可以在转换文档(回调...)等时与
其他进程通信。



它不甚至不得不成为司机。如果您的端口程序和其他Erlang代码之间没有通过许多
数据,那么您可以
考虑编写一个简单的端口(这更容易)。


I'd like to get a real XSLT processor working with erlang. Which would be the best interface, nif or port driver? According to the nif documentation, nif calls block the runtime, so they should not take long. Is processing a long xml document too long?

Also, I'd like to allow erlang callbacks during the transformation. Does that seem possible? Possible with nif but not port drivers or vice versa?

I've never written any C, so I figured this would be good introduction. Xalan is C++. I assume nif can work with that, right?

解决方案

I would recommend building a port driver.

The NIF facility is a way to add new built-in functions to the languageand speed up things that would be too slow to implement in pure Erlang.NIFs are considered experimental anyway, so the interface mightchange radically in future releases.

Writing a port driver means implementinga C (or C++) shared library that behaves like a whole erlang process.This allows for greater flexibility as you can communicate withother processes while transforming a document (callbacks...), etc.

It doesn't even have to be a driver. If you don't pass lots ofdata between your port program and other Erlang code you mightconsider writing a plain port instead (it's easier).

这篇关于Erlang:与Xalan接口:端口驱动程序或nif?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-09 03:32