[erlang-questions] How to get pid number in NIF code?

Sverker Eriksson sverker@REDACTED
Wed Sep 28 20:35:11 CEST 2011


Yes, ErlNifPid is typically the size of one word. You can type cast it 
to an integer type of equal size to get a "process number".

/Sverker, Erlang/OTP

Robert Virding wrote:
> Someone must correct if I am wrong here but I don't think that an ErlNifPid takes much space. As I understand it is not the whole process structure, just a reference to it. From erl_nif.h:
>
> #ifdef HALFWORD_HEAP_EMULATOR
> #  define ERL_NIF_VM_VARIANT "beam.halfword" 
> typedef unsigned int ERL_NIF_TERM;
> #else
> #  define ERL_NIF_VM_VARIANT "beam.vanilla" 
> typedef unsigned long ERL_NIF_TERM;
> #endif
>
> ...
>
> typedef struct
> {
>     ERL_NIF_TERM pid;  /* internal, may change */
> }ErlNifPid;
>
> But someone more knowledgeable should confirm this.
>
> Robert
>
> ----- Original Message -----
>   
>> On Wed, Sep 28, 2011 at 4:48 PM, Tony Rogvall <tony@REDACTED>
>> wrote:
>>     
>>> I do not think there is a way to extract that number (except for a
>>> small
>>> hack, of course)
>>> Care to tell the reason behind why you need it ?
>>> /Tony
>>>
>>>       
>> Hmm, I'm writing a NIF library to let erlang process communicate with
>> external hand. we call that as "hand", it is similar with erlang
>> process, but with different number reference, hand is range from
>> 0-65535.
>>
>> So in this NIF library I must remember the mapping of
>> "process<->hand", actually I only run this in one node, with process
>> like <0.X.0>,
>> which I only care about process number, that's why I want to get
>> process number, not whole pid structure.
>>
>> Of course I can store all "ErlNifPid<->hand index", but that will
>> consume a lot of memory.
>>
>> I think erts should provide API or macro for get process number for
>> some use case.
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions@REDACTED
>> http://erlang.org/mailman/listinfo/erlang-questions
>>
>>     
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
>   




More information about the erlang-questions mailing list