📄 gc and pf pseudocode
字号:
Memo #814 (2340)
Received: from technetium.cix.co.uk (technetium.cix.co.uk [194.153.0.53])
by nickel.cix.co.uk (8.9.3+Sun/8.9.1) with ESMTP id CAA01018
for <cweir@cixcouk.compulink.co.uk>; Tue, 11 Jan 2000 02:25:36 GMT
Received: (from root@localhost)
by technetium.cix.co.uk (8.9.3+Sun/8.9.3) id CAA29038
for cweir@cixcouk.compulink.co.uk; Tue, 11 Jan 2000 02:25:35 GMT
Received: from kaukau.mcs.vuw.ac.nz (kaukau.mcs.vuw.ac.nz [130.195.5.20])
by technetium.cix.co.uk (8.9.3+Sun/8.9.3) with ESMTP id CAA29025
for <cweir@cix.co.uk>; Tue, 11 Jan 2000 02:25:30 GMT
X-Envelope-From: kjx@MCS.VUW.AC.NZ
Received: from circa.mcs.vuw.ac.nz (circa.mcs.vuw.ac.nz [130.195.5.12])
by kaukau.mcs.vuw.ac.nz (8.10.0.Beta6/8.10.0.Beta6) with ESMTP id e0B2PSM21455;
Tue, 11 Jan 2000 15:25:28 +1300 (NZDT)
Received: (from kjx@localhost)
by circa.mcs.vuw.ac.nz (8.9.2/8.9.2) id PAA08492;
Tue, 11 Jan 2000 15:25:26 +1300 (NZDT)
Date: Tue, 11 Jan 2000 15:25:26 +1300 (NZDT)
Message-Id: <200001110225.PAA08492@circa.mcs.vuw.ac.nz>
From: James Noble <kjx@MCS.VUW.AC.NZ>
To: cweir@cix.co.uk
Subject: Code Example: GC
X-UIDL: d37c2b6e9d92eaf849e1ca39b52c8925
GC CODE EXAMPLE --- Pass #1
the text below is cut from the chapter.
Q: do you have the test cases for the reference-counting example?
After thinking a bit, those tests should all apply to the GC version.
[this example is not even pseudo code, needs to be completed]
[show how to add a simple, stack-based mark-sweep GC to the example from the reference counting pattern.]
class GarbageCollectedThing: public ReferenceCountedThing {
// should this just be thing??
public:
void mark();
void sweep();
protected:
bool markBit;
};
void setupPhase() {
//for all objects, set markBit to FALSE
//should be done on creation
}
void markPhase() {
for (r = root; r < lastRoot; r++) {
r.mark(); };
}
void mark() {
if (markBit) return;
markBit = TRUE;
for (r = all_my_fields; r < lastField; r++) {
r.mark(); };
}
void sweepPhase() {
for (p = first_object; p < lastObject; p++) {
if (p.markBit) {
p.markBit = FALSE;
} else {
delete p;;
}
}
Note that this example can be extended to recompute reference counts -
the mark phase should just increment an integer instead of setting a
bit. [illustrate this in the final example]
Memo #815 (1777)
Received: from technetium.cix.co.uk (technetium.cix.co.uk [194.153.0.53])
by nickel.cix.co.uk (8.9.3+Sun/8.9.1) with ESMTP id CAA01299
for <cweir@cixcouk.compulink.co.uk>; Tue, 11 Jan 2000 02:27:37 GMT
Received: (from root@localhost)
by technetium.cix.co.uk (8.9.3+Sun/8.9.3) id CAA29377
for cweir@cixcouk.compulink.co.uk; Tue, 11 Jan 2000 02:27:37 GMT
Received: from kaukau.mcs.vuw.ac.nz (kaukau.mcs.vuw.ac.nz [130.195.5.20])
by technetium.cix.co.uk (8.9.3+Sun/8.9.3) with ESMTP id CAA29369
for <cweir@cix.co.uk>; Tue, 11 Jan 2000 02:27:34 GMT
X-Envelope-From: kjx@MCS.VUW.AC.NZ
Received: from circa.mcs.vuw.ac.nz (circa.mcs.vuw.ac.nz [130.195.5.12])
by kaukau.mcs.vuw.ac.nz (8.10.0.Beta6/8.10.0.Beta6) with ESMTP id e0B2RVM21490;
Tue, 11 Jan 2000 15:27:31 +1300 (NZDT)
Received: (from kjx@localhost)
by circa.mcs.vuw.ac.nz (8.9.2/8.9.2) id PAA08236;
Tue, 11 Jan 2000 15:27:30 +1300 (NZDT)
Date: Tue, 11 Jan 2000 15:27:30 +1300 (NZDT)
Message-Id: <200001110227.PAA08236@circa.mcs.vuw.ac.nz>
From: James Noble <kjx@MCS.VUW.AC.NZ>
To: cweir@cix.co.uk
Subject: Code Example: PF
X-UIDL: 213463a009b40940688bd331330c55d4
text pulled from Partial Failure in the Arch chapter.
[example is in pseudo code, needs to be translated into real code]
Font findFont(String fontDescription) {
If fontCache.includes(fontDescription)
return fontCache.get(fontDescription);
Font f; // stores possible fonts
Try { // create a font
f = new Font(fontDescription);
}
catch (OutOfMemory oom) {
// on this exception, f will be nill
// don't rethrow the exception yet
}
if (f != null) {return f;}
if ((f = fontCache.findmatching(fontDescripton)) != nil) {
return f; }
if (cachedSystemFont != null) {return cachedSystemFont;}
throw OutOfMemory(self);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -