Removing eterm from NifEnv.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Removing eterm from NifEnv.

Ilya Khaprov

Hello,

 

I copy (enif_make_copy) an eterm to private NifEnv inside Nif.

Later I want to remove that eterm from the NifEnv (actually I want to free memory, but I guess this means removing from NifEnv’s heap).

How to do this? I know about enif_free_env, but this function clear entire env.

 

Thank you,

Ilya

 

 


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Removing eterm from NifEnv.

Lukas Larsson-8
Hello,

On Sat, Nov 18, 2017 at 8:20 PM, Ilya Khaprov <[hidden email]> wrote:

I copy (enif_make_copy) an eterm to private NifEnv inside Nif.

Later I want to remove that eterm from the NifEnv (actually I want to free memory, but I guess this means removing from NifEnv’s heap).

How to do this? I know about enif_free_env, but this function clear entire env.


It is not possible to free an individual term from a nif environment. If you want to have that kind of granularity, you have to create one environment per term that you want to individually collect. If the allocation cost of a new env is too large for your application, you could pool env's and use enif_clear_env to re-cycle env's into the pool.

Lukas

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Removing eterm from NifEnv.

Ilya Khaprov

Thanks! I think I can group my terms to reduce allocations/garbage collections.

 

Best regards,

Ilya

 


From: Lukas Larsson <[hidden email]>
Sent: Monday, November 20, 2017 10:05:15 AM
To: Ilya Khaprov
Cc: Erlang Questions
Subject: Re: [erlang-questions] Removing eterm from NifEnv.
 
Hello,

On Sat, Nov 18, 2017 at 8:20 PM, Ilya Khaprov <[hidden email]> wrote:

I copy (enif_make_copy) an eterm to private NifEnv inside Nif.

Later I want to remove that eterm from the NifEnv (actually I want to free memory, but I guess this means removing from NifEnv’s heap).

How to do this? I know about enif_free_env, but this function clear entire env.


It is not possible to free an individual term from a nif environment. If you want to have that kind of granularity, you have to create one environment per term that you want to individually collect. If the allocation cost of a new env is too large for your application, you could pool env's and use enif_clear_env to re-cycle env's into the pool.

Lukas

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions