Optimize registerSharedResource function

Replace a linear search for legacy resources
by a data member that counts them. Also use
the std::make_shared function instead of new.