[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: reference counting
- From: 云风 Cloud Wu <cloudwu@...>
- Date: Tue, 16 Apr 2019 09:55:13 +0800
Jim <email@example.com> 于2019年4月14日周日 下午6:41写道：
> how about making it possible to manage certain objects
> provided by C code by reference counting instead of
> garbage collection when the programmer indicates so ?
I'm working on a modified lua vm these days. It implements a
thread-safe mixed gc , which
mix a deferred reference counting and mark-sweep gc.
My goal is to share constant GCObject (such as TString and TProto)
with in multiple lua vm.
We can copy a GCObject to another lua vm by reference instead of deep-copy.
The main idea is :
1. Add a SHARED bit in marked of GCObject. When this bit is set, Its
life span is managed by a deferred reference counting system.
2. Shared GCObjects are always white, in the stage GCSpropagate, put
its pointer into a MARKED set instead of touching the marked bits.
3. in the stage GCScallfin , send this MARKED set to the GC thread ,
and GC thread will decease the reference counts of GCObject that is
not in this set but was in the vm.