问题标签 [erlang-nif]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
erlang - Calling NIF in Erlide IDE
Is it possible to call NIF functions from an Erlang program using Erlide if so is there any tutorial,article to help me run my first example
c - Erlang,在函数之间传递一个 nif 对象
C nif code
我在函数中写了一个and new
,它创建了一个堆栈结构enif_alloc_resource
并返回它。当我使用函数时enif_make_resources
,它总是<<>>
以erlang返回。
这是我的 C 代码:
现在函数new_nif
总是返回<<>>
,但我检查res
不是NULL
!问题是什么?
c - Erlang, Is it possible to reload or upgrade a nif library without restart the shell?
I have a nif library and every time i recompile it, I must restart the shell to reload or upgrade this library.
Here is my erlang code:
Every time i compile the erlang module, this error occurs:
and when i call init/0
function, this error occurs:
{error,{reload,"Reload not supported by this NIF library."}}
Is there anyway to fix this problem and load new nif library without restarting the shell?
erlang - 从 NIF 调用 Erlang 函数
是否可以从 NIF 调用 Erlang 函数(回调函数)?
我阅读了文档(http://www.erlang.org/doc/man/erl_nif.html),但没有找到如何做到这一点。
c - unicode collation NIF running slower than Pure Erlang implementation
I'm trying to optimise existing unicode collation library(written in Erlang) by rewriting it as a NIF implementation. Prime reason is because collation is CPU intensive operation.
Link to implementation: https://github.com/abhi-bit/merger
Unicode collation of 1M rows via Pure Erlang based priority queue:
Unicode collation of 1M rows via NIF based binomial heap:
This is unusual, I was expecting it to be probably ~10X faster.
I turned on eprof
/fprof
but they aren't of much use when it comes to NIF modules, below is what eprof
said about the prominent functions
I'm sure, NIF implementation could be made faster because I've a pure C implementation of unicode collation based on binary Heap using dynamic array and that's much much faster.
Specific questions I've here:
- How much slowdown is expected because of Erlang <-> C communication in a NIF module? In this case, slowdown is probably 30x or more between pure C and NIF implementation
- What tools could be useful to debug NIF related slowdown(like in this case)? I tried using
perf top
to see the function call, top ones(some hex addresses were showing) were coming from "beam.smp". - What are possible areas that I should look at optimising a NIF? For example: I've heard that one should keep data being transferred between Erlang to C and vice-versa minimal, are there more such areas to consider?
c - 使用 Erlang 的 NIF,我应该如何在 ERL_NIF_TERM 上使用 malloc?
我正在使用 Erlang 的 NIF,C 函数的结果是一个数组,我想以三点元组列表的形式将它发送回 erlang,每个元组都是两个双精度数的元组。
要创建这个数组,目前我正在这样做:
到目前为止,它似乎奏效了。但它是正确的吗?我的理由是,在数组的每个单元格上,ans
我有 6 个双精度数,每个双精度数为ERL_NIF_TERM
,所以我根据这个进行分配。
但这是真的吗?
我应该数元组吗?
无论如何大小是ERL_NIF_TERM
多少?double insideERL_NIF_TERM
与 int inside 的大小相同ERL_NIF_TERM
吗?一个 2 个整数的元组也是一个ERL_NIF_TERM
,它的大小是否相同?
c - Erlang NIF 数字返回类型
我正在尝试使用 NIF,但我对 Erlang 正在使用的数字类型感到困惑,因为我的精度有些奇怪。
这是一个例子:
从一个看起来像这样的 NIF 内部:
结果我得到了1
一个。
这与 C 层没有保持正确的数字“大小”有关吗?或者这enif_(get|make)_long
不是处理这种大小的数字的正确方法?或者仅仅是 NIF 不能处理这么大的数字?
c - Erlang nif 不升级
我用nif
erlang写了一个库。我也写load
,upgrade
和unload
功能。
这是我的代码:
在 erlang shell 中,我加载这个nif
并运行checksum
函数,它返回123
,一切都很好!
checksum
之后,我更改to的返回值并使用命令123456
编译和加载nif
to erlang vm 。l(mynif)
这就是问题所在!如果我运行checksum
函数,返回值必须是123445
但它仍然是123
并且nif
尚未升级。
问题是什么?我搜索了很多并测试了一些示例和库,例如jiffy
但没有用。
erlang - Erlang 可以像使用 C(例如 NIF)那样与 Go 交互吗?
我的 Erlang 项目中有一个 C NIF,由于它依赖的库(不稳定的库或我需要的库不存在),它有局限性。我认为我可以在 Go 中做我想做的事。Erlang 可以像这样与 Go 接口吗?
c - 来自创建线程问题的 Enif_send 函数
我试图从创建的线程调用 enif_send 。主要是,我有一个 erlang 进程,它监听从我的 nif 发出的接收到的消息。
首先,在我的 enif 函数中,我得到了我的 erlang 进程的 pid 并转换它,然后我调用 enif_send 发送消息,如下所示:
在这个阶段之前,我可以向我的 erlang 进程发送消息。
之后,我生成了一个 enif_thread 并将 env 和 pid 作为参数传递给它,我尝试从我的线程中调用 enif_send,例如:
但是当我用 enif_is_pid 检查 pid 时,我得到了一个无效的 pid,即使它是在产生线程的函数中检查的同一个 pid,因此发送失败。请问有什么想法吗?