From: Godmar Back (gback@cs.utah.edu)
Date: Sun Dec 20 1998 - 02:30:45 EST
Or alternatively -- but maybe that's what you mean actually -- you could
implement all the functions needed for reference counting, and implement
the interim backward compatible solution on top.
Like so maybe:
Utf8Const* createUtf8Const(char *s, int n) {
c = hash.lookup(s, n)
if (c) {
addRefUtf8Const(c)
} else {
c = hash.insert(s, n)
c->ref = 1
}
return c;
}
unsigned addRefUtf8Const(Utf8Const* c) {
return ++c->ref;
}
unsigned releaseRefUtf8Const(Utf8Const* c) {
int o = c->ref - 1;
if (o == 0) {
hash.remove(c)
free c
return 0;
}
return c->ref = o;
}
Based on these functions, create these backward compatible functions:
Utf8Const* makeUtf8Const(char *s, int n) { // deprecated!
c = createUtf8Const(s, n);
if (addRefUtf8Const(c) > 1) // (*)
releaseRefUtf8Const(c);
return c;
}
void finalizeUtf8(Utf8Const* this) { // deprecated!
releaseRefUtf8Const(this) // only one ref, will free it
}
(*) if you don't like encapsulation, you could even access c->ref
directly here.
Make sure you don't forget to synchronize the reference counts properly.
- Godmar
This archive was generated by hypermail 2b29 : Sat Sep 23 2000 - 19:57:25 EDT