1
votes

what happens underneath in memory during message passing between two actors in scala/akka? say I have two actors Actor1 and Actor2 and Actor1 sends an arraylist of size 10000 to Actor2 which might contain integers or strings or objects.

What will happen in the memory? from what I hear so far is that "actors don't share memory but they share the state". so does that mean the The arraylist from actor1 will be copied over to actor2? but that sounds so inefficient and I couldn't find information to read about these things. any docs? there are so many examples about how actors can exchange ping pong messages and those examples are redundant.

1

1 Answers

2
votes

For actors on the same JVM

One of the akka message restriction is immutability. So you can share references to the same message object with different mailboxes. Each actor has mailbox - usually a queue which contains envelopes with messages. Each message is a reference to object. So when you send array just the reference is added to actor's mailbox and if it is immutable object no problems with shared data could occur.