Allocating memory in Erlang C NIF

Why use

void *enif_alloc_resource(ErlNifResourceType* type, unsigned size)

      

Unlike

void *enif_alloc(size_t size)

      

when trying to allocate memory from Erlang C NIF?

The link does not indicate much about the reasons.

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

+2


source to share


1 answer


enif_alloc_resource is used to create resources that are garbage collected by the vm when it is no longer in use. enif_alloc works the same as malloc, only uses the specific Erlang VM implementation, not malloc. Take a look at the documentation for ErlNifResourceType and the functions that use it for more details.



+3


source







All Articles