|
|
| Author |
Message |
|
| edw |
Posted: Thu Oct 12, 2006 11:26 am |
|
|
|
Joined: 08 Oct 2006
Posts: 2
|
Hi,
I have a Smalltalk background and got interested
in Erlang recently.
Having tried some tutorials and thought about
the language concepts, it occured to me that it is
impossible in Erlang to have cyclic data structures
(e.g. a list containing itself).
Is this really true, or am I missing something?
This would have a tremendous impact on the garbage
collector, I guess.
Is there a documentation somewhere about the
details of the Erlang garbage collector?
Thanks,
Wolfgang |
|
|
| Back to top |
|
| francesco |
Posted: Tue Oct 17, 2006 9:18 am |
|
|
|
User
Joined: 07 Jul 2006
Posts: 249
Location: London
|
Hi WOlfgan,
The closest you can get to cyclic datastructures is using funs in the tail of the list.
Code: -module(f).
-compile(export_all).
from(H) ->
[H|fun() -> from(H+1) end].
2> [H|T] = f:from(1).
[1|#Fun<f.0.61259012>]
3> [H2|T2] = T().
[2|#Fun<f.0.61259012>]
Regarding the GC, it is a generationincremental GC which is run on a per process basis when needed. There were many implementations of the VM in the early days (VEE, JAM, BEAM, plus Mike WIlliam's own, which was before my time), all experimenting with different variants of memory management. On top of that, tricks such as deallocating all the memory when a process dies, shared binary heap, no shared memory gives the concurrency and speed we see today, even if running in an interpreted environment. The best one won, andd has since constantly been improved. I am unsure of where it is documented, if at all. Your best bet is to scrounge the erlang mailing list archives
Francesco |
|
|
| Back to top |
|
| edw |
Posted: Thu Oct 19, 2006 7:44 am |
|
|
|
Joined: 08 Oct 2006
Posts: 2
|
Thanks Francesco,
I have thought about your example. I see that
it "feels" cyclic, but I don't recognize the cycle in
the memory structure.
With cycles in memory I mean 2 objects referencing
each other.
Thanks
Wolfgang |
|
|
| Back to top |
|
| vladdu |
Posted: Fri Oct 20, 2006 7:07 am |
|
|
|
User
Joined: 28 Feb 2005
Posts: 397
Location: Gothenburg, Sweden
|
Hi,
You can't have real cyclic data structures in Erlang. One way to see why not, is to consider that to make a structure cyclic you need to be able to update it in place. The Erlang semantics are non-destructive, so it doesn't let you do that.
See also http://www.erlang.org/faq/x479.html, 5.6
best regards,
Vlad |
|
|
| Back to top |
|
|
|
All times are GMT
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|
|