Use of mutex in destructors

Dmitry Olshansky dmitry.olsh at gmail.com
Fri Apr 27 06:04:25 PDT 2012


On 27.04.2012 16:54, Rene Zwanenburg wrote:
[snip]
>
> True, but what would using structs do to fix the problem?
>
> The reason I'm using (final) classes is because a resource can be used
> by multiple objects. If two meshes use the same texture, I don't want to
> load that texture twice.

Don't. If I still worth anything in GL texture is bound to an opaque 
uint of sorts. There is no problem copying this number around.
There is no point in holding multiple references to 42 ;) Just copy the 
number.

Reference to class is cleaner than pointer to
> struct.

Use struct as reference-like type with some alias this magic you may 
also gain interesting properties. This way you can hide inside a 
delay-loading scheme of sorts.
Say counting usage rates then once resource usage hits a margin you go 
through the whole list or resources releasing those that are rarely used.

Also let us not forget that each class instance holds monitor object. 
Even though it's lazying initialized it still occupies extra space.

-- 
Dmitry Olshansky


More information about the Digitalmars-d-learn mailing list