Erlang: Interfacing with Xalan: port driver or nif?

左心房为你撑大大i 提交于 2019-12-12 13:53:15

问题


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?


回答1:


I would recommend building a port driver.

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

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

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



来源:https://stackoverflow.com/questions/2910212/erlang-interfacing-with-xalan-port-driver-or-nif

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!