C
colin
Hi,
I need to cache various resource objects such as images for example,
wich might be referenced from multiple objects
(wich could be considered documents for ease of discusion)
and the idea is simply to make sure they arnt duplicated
as they take up considerable memory, so I can look up
to see if an existing copy exists.
however once they are in the cache how can I ensure they get released,
when they are no longer referenced, as now my cache list is referencing
them,
so the GC wont free them.
can I look at the underlying reference count and so release it from my cache
if the count is 1?
I cant seem to find how to do this, at least not inside c#.
I realy dont want to have to keep a track of seperate reference count as
this
is something I hoped id got away from with managed code.
or is there a way to find all existing objects of a certain class?
a couple of alternatives would be
1) to hold a wrapper wich releases the bitmap when it hasnt been used for
ages,
but can reload it when required from the source,
however this needs a reference to the source wich means that the source no
longer gets released
when its dereferenced.
2) to have a root item wich all source documents are referenced from and to
periodically
keep the cache up to date with this. this is probably much like the GC
operation.
however this is probably quite complicated and not all the source types are
under my control.
I thought I heard someone talk about such a cache, however when I tried to
look
there are so many other types of cache, relating to .net assemblies etc.
the images are actually textures for my 3d objects,
but theres other types too wich are large enought o try and avoid
duplicating.
many thanks
Colin =^.^=
I need to cache various resource objects such as images for example,
wich might be referenced from multiple objects
(wich could be considered documents for ease of discusion)
and the idea is simply to make sure they arnt duplicated
as they take up considerable memory, so I can look up
to see if an existing copy exists.
however once they are in the cache how can I ensure they get released,
when they are no longer referenced, as now my cache list is referencing
them,
so the GC wont free them.
can I look at the underlying reference count and so release it from my cache
if the count is 1?
I cant seem to find how to do this, at least not inside c#.
I realy dont want to have to keep a track of seperate reference count as
this
is something I hoped id got away from with managed code.
or is there a way to find all existing objects of a certain class?
a couple of alternatives would be
1) to hold a wrapper wich releases the bitmap when it hasnt been used for
ages,
but can reload it when required from the source,
however this needs a reference to the source wich means that the source no
longer gets released
when its dereferenced.
2) to have a root item wich all source documents are referenced from and to
periodically
keep the cache up to date with this. this is probably much like the GC
operation.
however this is probably quite complicated and not all the source types are
under my control.
I thought I heard someone talk about such a cache, however when I tried to
look
there are so many other types of cache, relating to .net assemblies etc.
the images are actually textures for my 3d objects,
but theres other types too wich are large enought o try and avoid
duplicating.
many thanks
Colin =^.^=