ADBlock is blocking some content on the site

ADBlock errore

A lot of GUI controls indicating different states

StackOverflow https://stackoverflow.com/questions/10815692


This question is very open and probably, the answer to this question will depend on the system, but say in average which is the best way to show a large matrix (say 128 elements) of different states?

  • Create one control for each cell and let GUI library deal with all events and stuff (In Windows 128 HWND:s)
  • Draw the entire matrix by using lower-level graphics primitives

Is there a difference in memory/CPU performance depending on choice? The number of states in my application is 4 for each cell so they need 2 bits each to represent their state. Each cell will be represented by an image related to the state.


Sure there is a difference. I will try to illustrate this and also the assumptions this is based on.

  1. Cost of a control = memory for control + event handlers for control + references to control + one extra control in event pipeline

  2. Benefit of "tight" control per cell mapping. Conceptually clean, simple code, easiest to think about.

  3. Cost of tight mapping : multiply the cost per control by the number of cells.

The alternative I'm about to suggest assumes that the cost delta between tight mapping and a loose "one ring" mapping is important.

alternative : just add one control that is registered for events only within the bounds of the whole matrix view you present, has a piece of code to determine the pointer position and what cell that corresponds to, and then updates only that cell depending on the user interaction there.

The advantages of this are you get the marginal cost of only one extra control but the benefit of handling interactions for the entire matrix. The marginal benefit or this control is much higher than for a single tight control. Aldo, the implementation cost is small as it is a common pattern and not too difficult.

Good luck!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow