[erlang-questions] Where is enif_keep_binary?

Anthony Ramine <>
Mon Aug 22 09:45:26 CEST 2011


Hi,

Are this binary big? If it is big enough, it won't be copied anyway and its refcounter will just be incremented.

Regards,

Le 22 août 2011 à 08:10, Max Lapshin a écrit :

> I start enif_thread_create and pass binary to there:
> 
> 
> static ERL_NIF_TERM yuv_x264(ErlNifEnv* env, int argc, const
> ERL_NIF_TERM argv[]) {
>   ....
>   enif_mutex_lock(x264->lock);
>   enif_inspect_binary(env, argv[1], &x264->yuv);
>   x264->has_yuv = 1;
>   enif_cond_signal(x264->cond);
>   enif_mutex_unlock(x264->lock);
>   return enif_make_atom(env, "wait");
> }
> 
> and in thread I make:
> 
> 
> while(1) {
>  while(!x264->has_yuv) {
>    enif_cond_wait(x264->cond, x264->lock);
>  }
> 
>  handle(x264->yuv);
> }
> 
> Problem is that binary get expired. How should I add refcounter to binary?
> Copy it to other env?
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions

-- 
Anthony Ramine / @nokusu
Dev:Extend — http://dev-extend.eu/
So as I pray, “Unlimited Erlang Works”




More information about the erlang-questions mailing list