liveBook · Manning

Data type

As explained in High Performance Unity Game Development

A specification of the kind of value a program element can represent and the operations and storage interpretation associated with it.

Choosing a type for enemy hit points affects both the values they can hold and the memory they use. Smaller types can reduce storage, but they are not automatically faster; performance varies across devices. section 2.6.1 section 2.6.2

Choose a type by checking the value range and the job the data must do:

  • Use int by default for runtime counters, indices, hit points, and IDs unless profiling shows another type is faster on target hardware. section 2.6.1
  • For saved or networked values, compare the required range with type size. A 10,000-HP maximum fits in short or ushort; use short if values may be negative. section 2.6.2
  • Test smaller types on the minimum target device when values update frequently. They may reduce memory or bandwidth while slowing runtime work. section 2.6.1 section 2.6.2
Figure 2.14 This figure shows two cache lines, one filled with ints and one with bytes, and shows that we can fit 4x more byte data than int data in a cache line.

The cache-line comparison illustrates why smaller values may increase cache density, though that alone does not guarantee faster execution. section 2.6

How High Performance Unity Game Development covers it

How deep it goes
Compares type sizes, ranges, and device-dependent performance, then gives selection guidance; it does not prescribe one fastest type across devices.
Examples
Uses byte-versus-int cache density, device timing comparisons, and a short hit-point array for enemies.
What you can do after
Evaluate type choices by value range, storage needs, and profiling results on target hardware.
How it connects
Connects data types to arrays, cache lines, CPU architecture, memory use, and network bandwidth.

Also explained in

Compare how 22 books explain data type →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of High Performance Unity Game Development. The section links point to the parts of the book it draws on.