On 1/22/2019 at 2:26 PM, pcmaster said:The troll manager might have a hash-map<Handle,Troll> style dictionary, in a naive implementation. Every time it's asked, it'll look into the hash-map and return nullptr if it doesn't find anything (or anything alive). And if it does find it, it can actually return a POINTER (!) but you must not store it for later use. Just use it and forget it. Next time, it might return a different pointer for the same handle, for example if it did some kind of defragmentation.
It is worst possible architrcture here. Becouse it move lifetime managment expences from event that happends only once during throll lifetime to access, that happends every frame for every warrior-throll pair. i.e. making O(n^2) task for every ftame from O(n) task that have to be perfoemed only once. It ever worse than using of weak_ptr that have same disadvantage, but have a O(1) access time instead of hash that have O(1) in best case only.