[erlang-questions] process dictionary, anyone?

Ulf Wiger (TN/EAB) ulf.wiger@REDACTED
Mon Apr 30 12:26:50 CEST 2007


 
Robert Virding wrote:
> 
> Ets and ports easily map onto processes/messages so except 
> for the process dictionary there is really only one 
> non-functional feature today and that is just 
> processes/messages. And the process dictionary.

What is it about the process dictionary that cannot
be mapped onto processes/messages?

Eshell V5.5.3.1  (abort with ^G)
1> c(pdict).
{ok,pdict}
2> pdict:init().
<0.45.0>
3> put(a,1).
undefined
4> put(a,2).
1
5> put(b,3).
undefined
6> get().
[{b,3},{a,2}]
7> put(c,3).
undefined
8> get_keys(3).
[c,b]
9> pdict:put(a,1).
undefined
10> pdict:put(a,2).
1
11> pdict:put(b,3).
undefined
12> pdict:put(c,3).
undefined
13> pdict:get_keys(3).
[c,b]
14> erase(a).
2
15> pdict:erase(a).   
2
16> get().            
[{c,3},{b,3}]
17> pdict:get().
[{c,3},{b,3}]

Not claiming that this is a particularly good
implementation of the process dictionary, but it
does illustrate compatible behaviour.

It's in fact *easier* to model the process dictionary
with processes and messages than it is to model ets
(partly because the ets interface is broader, but also
due to named tables, reentrant matching, tab2file(), 
access flags, etc.)

Ets is dirtier and encourages unsafe get/put programming
to a far greater extent than the process dictionary.


BR,
Ulf W
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pdict.erl
Type: application/octet-stream
Size: 2007 bytes
Desc: pdict.erl
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20070430/fbba1b79/attachment.obj>


More information about the erlang-questions mailing list