[erlang-questions] FFI for Erlang: patches and draft EEP

Alceste Scalas alceste@REDACTED
Tue Sep 11 16:21:03 CEST 2007


Il giorno mar, 11/09/2007 alle 15.14 +0200, Vlad Dumitrescu ha scritto:
> If the C side uses pointers to the internals of the Erlang binaries,
> aren't there going to be some nasty interactions with the garbage
> collector?

If the pointers are kept on some internal C structure *after* the
function call returns, then they may become "obsolete" if the GC decides
to move the binaries around.  In these cases, the C side should take
care of copying the data in a safe place.

The pointers, however, are safe during the function call itself [1].

Regards,

alceste

Notes:

  [1] If it's needed, the FFI BIFs could ensure that the binary is
      not moved during the call, e.g. if the GC runs on another
      processor/thread.
      However, I was not able to spot any existing BIF that does
      something like that: binary data is just accessed without
      worries. Maybe the Erlang Master Developers could say whether
      I'm wrong :-)

-- 
Alceste Scalas <alceste@REDACTED>
CRS4 - http://www.crs4.it/




More information about the erlang-questions mailing list