Law Edward
Law Edward

Reputation: 3

In erlang, which is better, procees dictionary or its state

As a newbie, I've learned that process dictionary is stored in the process's own heap , and it can be used to storage private data in the process, but why don/ use the process's state

Upvotes: 0

Views: 389

Answers (2)

Mo Ein
Mo Ein

Reputation: 47

OTB gen(like gen_server , gen_fsm , gen_event , ...) provide design for store data in actor segment and actual implementation of state is message wait in receive block and handle in gen and act like a variable so no using possess dictionary, in it's safe. if you want to use global variable you can use application enviroment value .

Upvotes: 0

Pascal
Pascal

Reputation: 14042

Avoid to use the process dictionary, except for some specific case, for example to store some debug information. If you use it to store a state information, you create a "side effect". This means that the return value of the function does not depend only on the parameters but also on the hidden state of the process dictionary. Thus it is more complex to test and maintain.

Upvotes: 4

Related Questions