Search code examples
c++staticmembers

Should lookup tables be static


I have a Message class which parses text messages using lookup tables. I receive a lot of messages and create and destroy a lot of objects so I thought I declare those lookup tables as static members to prevent initializing the same tables with the same values again and again.

Is it the correct approach or there's more appropriate C++ way?

Thanks.


Solution

  • This sounds like the right way to do it, although I'd expect the compiler to optimize this. Have you benchmarked your application and does declaring the tables as static speed it up?

    Also note that if you have many large lookup tables, performance will increase, but the tables will be hold in memory all the time.