如何安排收集周期自定义标记 - 清除收集器? [英] How to schedule collection cycles for custom mark-sweep collector?
问题描述
我已经写了后记虚拟机一个简单的垃圾收集器,和我有困难,设计一个体面的一套时候做一个集合(当空闲列表太短?)规则以及何时分配新空间(当有使用大量的空间吗?)。
I've written a simple garbage collector for a Postscript virtual machine, and I'm having difficulty designing a decent set of rules for when to do a collection (when the free list is too short?) and when to allocate new space (when there's a lot of space to use?).
我已经写自下而上,到目前为止,但这个问题涉及到顶层设计。所以,我觉得我站不住脚。
所有对象进行管理和访问只能通过运营商的功能,所以这是一个收藏家在 C,不是为的温度。
I've written bottom-up so far, but this question involves top-level design. So I feel I'm on shaky ground. All objects are managed and access is only through operator functions, so this is a collector in C, not for C.
主要分配函数被调用 gballoc
:
unsigned gballoc(mfile *mem, unsigned sz) {
unsigned z = adrent(mem, FREE);
unsigned e;
memcpy(&e, mem->base+z, sizeof(e));
while (e) {
if (szent(mem,e) >= sz) {
memcpy(mem->base+z, mem->base+adrent(mem,e), sizeof(unsigned));
return e;
}
z = adrent(mem,e);
memcpy(&e, mem->base+z, sizeof(e));
}
return mtalloc(mem, 0, sz);
}
我敢肯定这是废话不知道什么所有的类型和功能的意思,所以这里的相同功能的伪code:
I'm sure it's gibberish without knowing what all the types and functions mean, so here's pseudocode of the same function:
gballoc
load free list head into ptr
while ptr is not NULL
if free element size is large enough
return element, removed from list
next ptr
fallback to allocating new space
所以这是一个简单的首次适应算法没有雕刻。(但保留分配它们的大小,所以对于小对象重用的大空间可以再次大对象被重用,后)
So it's a simple "first-fit" algorithm with no carving (but allocations retain their size; so a large space reused for a small object can be reused for a large object again, later).
但是,当我应该叫收集()
?
编辑:
在code和相关模块的其余部分已张贴在comp.lang.postscript,在螺纹:
的http://groups.google.com/group/comp.lang.postscript/browse_thread/thread/56c1734709ee33f1#
推荐答案
有几个适用的哲学:
- 请垃圾收集负隅顽抗避免分配中扩展堆。这可能是最常见的策略。
- 定期做垃圾回收,像每百分配或释放。在某些情况下,这可能不让碎片减少垃圾回收的整体努力一发不可收拾。
- 请不要做任何垃圾收集。总是有可能的策略,尤其是对短期或简单的程序。
作为垃圾收集的显影剂,可能希望给策略的选择到应用,因为它可能会知道,这将是最有效的。当然,如果它没有一个preference,你应该选择一个默认值。
As a developer of garbage collection, it might be desirable to give the choice of strategy to the application since it might know which will be most effective. Of course, if it doesn't have a preference, you should choose a default.
这篇关于如何安排收集周期自定义标记 - 清除收集器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!