Smartness overload – addendum
July 4, 2010 – 9:33 pmIn my previous note I mentioned that IDs are my favourite form of weak references. By pure coincidence, just recently Noel made one of his Inner Product articles public and it deals with very related subject. As a matter of fact Noel’s implementation of HandleManager has been a starting point for the one I use for my home projects. I use it not only for dealing with resources, but as a general ID->pointer resolver. It can be made a little bit easier if you don’t need to handle heterogenous objects. My modifications include:
- getting rid of a type field (instead, I have multiple pools/managers),
- optimizing Get() method a little bit. I do not test if entry is active, I only compare counters. To make sure it works as intended, I modify counter when releasing resource/object, not when acquiring it. This let me to get rid of one comparison, not a big deal, but every little bit helps.
Noel made his implementation public, I encourage everyone to download it and take a look, it’s very simple, yet helpful piece of code.










