Resource Management... Howto?

Jarrett Billingsley kb3ctd2 at yahoo.com
Mon Jul 9 14:16:08 PDT 2007


"Samuel Winchenbach" <swinchen at eece.maine.edu> wrote in message 
news:f6tlr6$1je2$1 at digitalmars.com...
>
> auto h = resource.create();
> resource.destroy(h);
>
> something like that.  avoid reference counting and just rely on the 
> developer using the resource manager to free the resource.
>
> Opinions on this?

One thing you can do is forget about the "nondeterministic destruction" rule 
and free your resources in the dtor of your resource classes anyway (this 
would also remove the need for a "reference" class -- just use the Texture 
class directly).  Then run the GC periodically.  If you're tight with mem 
allocation in other areas, this could be pretty efficient.  The downside is 
that you still have the possibility of long GC cycles (though you have the 
possibility of long allocations without a GC too..), and the resources 
wouldn't be freed _immediately_ as with refcounting.  Though, if you called 
the GC once every 10 seconds or so, I doubt that would be too much of a 
problem, and if you called the GC right before you loaded a bunch of new 
resources, for example, it definitely wouldn't be a problem.

>
> Also fonts have been bugging me.  Fonts can have the same file name, but 
> different settings (italic, bold, underlined, pt. size, etc...)  so 
> instead of having: FontList[char[]] I think I might have 
> FontList[FontDescriptor[]].   This seems reasonable right?

It'd probably be FontList[FontDescriptor], but yeah that sounds fine.  As 
long as two instances of FontDescriptor compared equal with the same 
members, and as long as they hashed to the same value as well.

> So I think my resource manager will have both an AA and a descriptor for 
> each type of resource.   Still working on how to make it somewhat generic. 
> I would really like there to only be one type of handle, one type of 
> createResource and one type of freeResource.  I am not sure this is 
> feasible though.   At this point I am just blabbing...

Is there any reason why you'd need one kind of resource handle?  I mean, you 
can't use a texture in place of some other resource; wouldn't this be 
breaking type safety? 




More information about the Digitalmars-d-learn mailing list