Perturbatio #1 A more optimized way of doing it would be to have a global type counter, and simply increment or decrement it by one each time you create or delete an instance of that type.