[erlang-questions] yet another way to communicate between processes

Kostis Sagonas kostis@REDACTED
Fri Jan 21 13:42:36 CET 2011


Matthias Lang wrote:
> How many ways can processes communicate?
> 
>   - Message passing, obviously.
> 
>   - ...
> 
>   - Hipe lets you destructively update binaries

I understand the point of Matt's message, but the phrasing of the last 
item on his list is a bit exaggerated.

HiPE does NOT let you destructively update binaries!

HiPE implements (mostly for its own consumption) a byte/bit array 
interface that just happens to currently use binaries as its underlying 
representation. The term which is returned is really opaque and cannot 
be forged.

42> hipe_bifs:array(42,0).
1341051852164310958483470496723442421146438490410398599188212234810775184469773903675250096414324892498977265047852129698138433859883549051251117502043807487620028142015641359445529065620292765912887098241208265312044730234611304175737605272347266134465468817112674654480500333272504281215210377271949900335044555573928768066406428898637749039097161515519403482064915448724323249585518139188183055

You can not possibly pass a random binary to the appropriate BIFs and 
destructively update their contents.

43> Bin = << <<1>> || _ <- lists:seq(1,42)>>.
<<1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
   1,...>>
44> hipe_bifs:array_update(Bin, 2, 0).
** exception error: bad argument
      in function  hipe_bifs:array_update/3
         called as 
hipe_bifs:array_update(<<1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                                            1,...>>,
                                          2,0)

Of course, Matt is right that this mechanism could be used for 
communication: if one process does pass this array handle in a message 
to some other process, the other process can use this to read from or 
write to this array.

Cheers,
Kostis


More information about the erlang-questions mailing list