A short is a 2-byte signed integer with a range of −32,768 to 32,767. Use it for bounded whole-number data, such as enemy hit points, when reducing memory use or network payload size matters. section 2.6.2
Choose a smaller integer type only after checking its limits and performance:
- Ask how large the value can get; a short can hold 10,000 hit points, including negative values. section 2.6.2
- A short uses half the space of an int, but smaller types may be slower; test on the minimum target device. If compact storage is unnecessary, prefer int. section 2.6.2 section 2.7
Listing 2.22 Our enemy data class, with short hit point array
public class EnemyData
{
public Vector2[] Position;
public Vector2[] Direction;
public float[] Velocity;
public bool[] Alive;
public short[] HitPoints;
}This enemy data structure uses a short array for hit points. section 2.6.2
