Erlang VM

Raimo Niskanen raimo@REDACTED
Tue Mar 28 09:35:43 CEST 2006


It is a very reasonable question, not a stupid. It can probably
be found if you dig deep enough into some FAQ...

Every process has its own data heap and stack, so data
that is sent to another process gets copied. This is
to keep garbage collection on separate processes
independent of each other.

Common exceptions that have common storage for all processes:
* Non-small binaries (> 64 bytes).
* Ets-tables.
* The experimental Hybrid Heap Emulator has an additional
  heap for common data. And data that is sent to another
  process is placed on the shared heap. The compiler might
  in the future determine which data that will later
  be sent and allocate it on the shared heap. The garbage
  collector is still being worked on, though...
* The system can be designed to not store large data
  in many processes. Instead you can have a server process
  that holds the data; clients make querys and only
  store results while they are needed.



yani.dzhurov@REDACTED (Yani Dzhurov) writes:

> Hi guys,
> 
>  
> 
> I wondered how the Erlang virtual machine works with creating a lot of alike
> objects.
> 
> This is my function for example:
> 
> my_fun()->
> 
>   Tree = gb_tree(),
> 
>   :,
> 
>   foo(),
> 
>   bar(),
> 
>   baz().
> 
>  
> 
> And if a "spawn" this function into a hundred of processes will the Erlang
> VM machine create hundred of gb_trees, or it will create just one instance
> and a hundred references to it. Sorry if my question is pretty stupid but
> I'm very familiar with Erlang.
> 
>  
> 
> As far as I know in Java, if I have
> 
> String a = "abc";
> 
> String b = "abc";
> 
> The Java VM will create just one object string "abc" and point both 'a' and
> 'b' to that object, since string is immutable and there would be no
> collisions with using that object. In Erlang objects are immutable also,
> right ? So will the Erlang VM do the same as the Java one?
> 
>  
> 
> Thanks,
> 
>  
> 
> Yani
> 
>  
> 
> 

-- 

/ Raimo Niskanen, Erlang/OTP, Ericsson AB



More information about the erlang-questions mailing list