在二郎山çNIF分配内存 [英] Allocating memory in Erlang C NIF

查看:278
本文介绍了在二郎山çNIF分配内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么人会使用

void *enif_alloc_resource(ErlNifResourceType* type, unsigned size)

,而不是

void *enif_alloc(size_t size)

试图从一个Erlang NIFÇ分配内存时?

when trying to allocate memory from an Erlang C NIF?

引用不指定多少,为什么。

Reference does not specify much as to why.

http://www.erlang.org/doc/man/erl_nif。 HTML#enif_alloc

推荐答案

enif_alloc_resource用于创建它们是由虚拟机在收集时不再使用的垃圾资源。 enif_alloc工程就像malloc的,只使用一个Erlang VM具体实施,而不是操作系统的malloc。看看为ErlNifResourceType的文档和使用它的一些更详细的功能。

enif_alloc_resource is used to create resources which are garbage collected by the vm when not used any more. enif_alloc works just like malloc, only is uses an Erlang VM specific implementation rather than the OSs malloc. Take a look at the documentation for ErlNifResourceType and the functions which use it for some more details.

这篇关于在二郎山çNIF分配内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆