Can I remove an element from a global associative array from within a class destructor?

realhet real_het at hotmail.com
Sat Aug 3 08:55:33 UTC 2019


On Saturday, 3 August 2019 at 05:33:05 UTC, Jonathan M Davis 
wrote:
> On Friday, August 2, 2019 5:13:10 PM MDT realhet via 
> Digitalmars-d-learn wrote:
>> Hi,
>> ...

Thank you!

Now I have 2 solutions in mind:
1. If I only want to track the count and totalBytes for a 
specific kind of reference, I will be able update those from the 
destructor.
2. If I wanna track all instances of resources, I will use 2 
classes instead of one class and an associative array:
- When I create a resource, I create class1 for the statistics, 
and store them in an assocArray. Then I create a class2 and 
inside it there is a reference to class1. Class2 will be given to 
the user. If the user don't use it anymore, the GC will destroy 
class2, and in it's destructor it will mark a field in class1. 
And it will be periodically checked, so the actual deletion of 
the GLBuffer and other statistics will be done by me.
With millions of resources it will be slow, but for a few 
thousand it's ok. (I can also put them in a hierarchy, but the 
most important is not to alloc/dealloc from ~this())

I hope it will be stable :D

Thank You again!




More information about the Digitalmars-d-learn mailing list