Resource Management... Howto?
Samuel Winchenbach
swinchen at eece.maine.edu
Sat Jul 7 05:59:24 PDT 2007
downs wrote:
> I've been thinking about a better way to do this.
> How about we (ab)use the GC? That is, each returned resource with the
> same index contains a pointer to some throwaway object. This object's
> address is stored together with the AA itself, but encoded somehow
> (negative? xor with a constant?) so that the GC doesn't find this relation.
> Now, whenever all resources of that type have been deleted, and the GC
> runs, the object will not have anything obvious pointing towards it
> anymore; thus, the GC will delete it. Before that, it will call the
> object's destructor, which, in turn, will delete the object's entry from
> the AA :)
> --downs
>
> PS: I have no idea if that could work; also, you'd be relying on the GC
> which the spec says _not_ to rely upon. Evil :)
> PPS: Not guaranteed to work. Use at own risk.
Wow, I think that might be a little advanced for me. I am on
approximately week 2 of D. Coming from ANSI C (with a touch of C++)
this is quite a shock for me. If you have any example code of this in
action I would love to see it though :)
Sam
More information about the Digitalmars-d-learn
mailing list