How much can an unodered_map access cost hamper the performance of a game?

0

Can access cost to unordered_map cause FPS drop in a game if accessed thousands of times per second?

class var
{
public:
    template < typename t = double > 
    static inline auto get( const std::string& var_name ) -> t& 
    { 
         return ( t& ) m_vars[ var_name ]; 
    }
private:
    static inline std::unordered_map< std::string, double > m_vars;
};

// Isso vai ficar rodando infinitamente em vários loops
// Não vai ser apenas uma vez que vou chamar o método get, vou chamar varias e varias vezes em vários loops diferente
// Acredito que o acesso ao map vai comprometer muito o desempenho do jogo ocasionando perda de fps
if ( var::get< bool >( "ativar_efeitos" ) )
{

}
    
asked by anonymous 02.08.2018 / 19:15

1 answer

0

Difficult to respond without a context, but it is highly unlikely that this will significantly affect, at least not by it. Of course the function that calculating the hash code used to map, the quality of it, the keys you use, and how it is used in general could affect something, but still, it would have to be all very tragic to affect a little. This running infinitely worries a little more, I do not know if it should, but the problem has nothing to do with the map.

And if you need a map, it's no use changing to something else. If you can use something else good and it's something better then you should use it.

I also wonder if this is a good strategy, or if C ++ is the appropriate language if you are doing this. But only a very detailed context to know.

I do not even know if this code should be written like this. In the posted form it should not.

To be honest, the question is a little naive, which probably indicates that it will make several other errors much more serious than this one that will affect much more, and will not even notice.

    
02.08.2018 / 19:28