Quote:
Originally Posted by codeNinja
(Post 3660021)
This is for a Python-like programming language project.
|
In a Python-like language, you (as language implementor) should be in more control of pointers and/or references. You should use that control to do something much better than a write barrier to detect changed references.
Quote:
I have used Boehm's garbage collector before, but I'm worried that it will have noticeable pause times (unacceptable for interactive programs).
|
How big a pause would be noticable? "interactive" covers a wide range. For some kinds of interactive a 100ms pause would be OK; for other kinds a 10ms pause would be a problem.
Quote:
I have been thinking of simply writing my own.
|
Even if you write your own, avoiding the pause may be very hard. What is the central concept of the method you would use to avoid a pause?
Quote:
Some kind of write barrier mechanism that will notify my collector when something is written to a part of the heap
|
What fraction of the writes do you expect to be pointer updates vs. what fraction of the heap do you expect to need a write barrier at typical times?
In a language (like Python) with much less flexible pointer manipulation than C, it would be much simpler to load all pointer writes rather than load a heap position based subset of all writes. The load per write would also be much lower. Unless you expect the barrier to cover only a tiny fraction of writes, working at the pointer level would be faster as well as simpler.
Quote:
A way for me to know the addresses and sizes of the stack, heap and global storage (the root sets)
|
That would seem to be entirely in your control. Why would you want to rewrite something as hard as a GC without taking control of the memory pools. But if you do take control of the memory pools, you trivially know where they are. That also lets you exclude a lot of built in memory use (that you can manage more efficiently yourself) from the GC.
If you want a general GC for use in a language as flexible (rat pointer math) as C, do you really expect to be able to do better than Boehm's? If you want to make use of whatever ways your language has less pointer flexibility than C, then you need some focus on that.
Quote:
Originally Posted by codeNinja
(Post 3660822)
The problem with smart pointers and reference counting is that objects forming cycles of references will never be deallocated.
|
I would expect such cycles to be very rare. Certainly, you can't just ignore them and let lost memory build up when cycles occur. But it is a shame to load an entire design with large performance/complexity costs just to cover an obscure case.
It should be simpler to create a system based
mostly on reference counting with a background GC (cooperating with the reference counting) to pick up memory lost to cycles.
In addition to catching almost all disconnected memory (so the GC would have much less work to do) the reference counting could also eliminate the need for anything like a write barrier.