[erlang-questions] How do I create a specific ref() ?

Witold Baryluk baryluk@REDACTED
Thu Jul 30 11:06:03 CEST 2009

Dnia 2009-07-30, czw o godzinie 16:40 +0800, Thijs Terlouw pisze:
> How do I create a new ref() for a specific value (based on an old #Ref)?
> I know I can use "erlang:make_ref() -> ref()" to get a new almost unique
> Reference.
> I can also use "erlang:ref_to_list(Ref) -> string()" to serialize a Ref to a
> String.
> It seems there is no "list_to_ref(String) -> ref()" function though, what's
> the reason for this?
> My use case:
> I am writing an async port program which is called from a gen_server() and I
> would like to prevent storing the a mapping {Seq -> From} in ETS. If I could
> just pass the serialized Pid + serialized Ref to the port program, my
> problems would be solved, because the port program could return the Pid +
> Ref and I deserialize them again.
> Cheers,
> Thijs

If think this is because after you serialize it to list, and original
Ref isn't used anymore, make_ref() can return the same value. Kind of
garbage collection (ref counting in VM?). If you would deserialize it
back using list_to_ref, there can be logical conflict, you will have
ref(), which is not unique anymore. So i think you need to remember
refs directly in VM. 

Witold Baryluk <baryluk@REDACTED>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: To jest cz??? wiadomo?ci podpisana cyfrowo
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20090730/39b8ec27/attachment.bin>

More information about the erlang-questions mailing list