[Exceptional C++ Style] Item 26 -- Data Formats and Efficiency

Ric Parkin ric.parkin at ntlworld.com
Mon Jan 31 09:40:02 EST 2005


Paul
> Somebody must have some comments? 

It's more of an observation.

The start of the answer to the guru question says "the point ...is to demonstrate that there can be a plethora of ways to represent the same information"

I'd say it also demonstrates that knowledge of the data is a huge part of coming up with more efficient ways. 


For example, by retricting it to legal chess games, a large number of impossible positions and moves can be ignored, which means you have a much smaller set to consider. (If you imagined a game where you could have any type of piece on any square, and any number can change at every move, then you *have* to store the entire board state, and solutions c onwards are ruled out)



It reminds me of an example that crops up often elsewhere - a lookup table, say a lookup up of an int given another int. Without any more information, something liek a std::map may be a suitable first choice. But if I tell you that the int to look up will be constrained to a known range (say 0-255) then a better solution could be an array using the value as an index.

Ric


-----------------------------------------
Email provided by http://www.ntlhome.com/





More information about the Effective-cpp mailing list