Why would one use
void *enif_alloc_resource(ErlNifResourceType* type, unsigned size)
as opposed to
void *enif_alloc(size_t size)
when trying to allocate memory from an Erlang C NIF?
Reference does not specify much as to why.
Why would one use
void *enif_alloc_resource(ErlNifResourceType* type, unsigned size)
as opposed to
void *enif_alloc(size_t size)
when trying to allocate memory from an Erlang C NIF?
Reference does not specify much as to why.
Copyright © 2021 Jogjafile Inc.
enif_alloc_resourceis used to create resources which are garbage collected by the VM when not used any more.enif_allocworks just likemalloc, only is uses an Erlang VM specific implementation rather than the OSsmalloc. Take a look at the documentation forErlNifResourceTypeand the functions which use it for some more details.