Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Data representation

Because of our memory quality criteria C1a and C1b, we must pay attention to how data for the widgets and the graphics phase are represented and organized.

Configurations and states

We split every widget into a configuration and a state to meet C1b. The configuration doesn’t change and can be embedded in the program binary. Assuming that the program is not loaded into volatile memory, this saves volatile memory. Conversely, the state can change during the execution of the program. It is stored in the volatile memory.

While some data is always categorized as either a configuration or a state, depending on the use case, some data can be either. For instance, if a user interface is always displayed on screen at a specific size, then the bounding boxes of the widgets can be configurations. Conversely, the bounding boxes of dynamically created widgets are always part of their state.

Data structures

We heavily rely on data structure backed by arrays. This ensures a reduced use of memory and an efficient access and linear traversal.

The structure of the widget tree is implemented with an array where nodes are arranged in a prefix order. Each node indicates the number of nodes in its subtree and its height. This forms a sum tree. Each widget is associated to a node and is identifiable with the node index.

Dynamically created widgets are isolated such as most of the widget tree is static and is thus a configuration. These widgets can only be added to dynamic containers. A dynamic container uses a unique configuration for all its children widgets. This configuration acts as a template.

A widget tree configurations without its state is called a component.

Data layout

Data layout is particularly important in environments with limited memory. For example, combining a one-byte data type with a four-byte data type results in an eight-byte data type due to data alignment constraints. While this is fine for a single type, using arrays of such types waste a lot of memory. To avoid this situation we use a data-oriented technique named Struct of Arrays (SoA). Configuration and state of widgets are separated in several arrays.