Tier 1
Series 2
2B: Collections Audit
"In aviation, every ounce matters. If you fill a cargo plane with thousands of small, unorganized boxes, the weight shifts and the engine struggles.
In C#, Lists are your cargo. If you let them grow wildly without a plan, Unity has to stop the engine to find a bigger "rack" for your data. This creates GC Spikes—the stuttering you feel in a lagging game."
In C#, Lists are your cargo. If you let them grow wildly without a plan, Unity has to stop the engine to find a bigger "rack" for your data. This creates GC Spikes—the stuttering you feel in a lagging game."
The Concept: Fixed vs. Dynamic
Array [ ]: Fixed size. Extremely fast and lightweight.
List: Dynamic. Flexible but "heavy." Requires capacity management.
List
Red Flag Detected
The Audit: Spot the "Memory Drift" Error
You ask the AI: "Create a list to store enemies as they spawn."
// AI-Generated Code (Inefficient)
public List<GameObject> enemies = new List<GameObject>();
void SpawnEnemy(GameObject prefab) {
enemies.Add(Instantiate(prefab));
}
This list starts with a capacity of zero. As items are added, the list repeatedly doubles its size, forcing memory re-allocations that cause performance bottlenecks.
Elite Telemetry
Research shows "Elite" teams achieve 15% faster lead times by keeping AI on a "very tight leash."
- Small Batches Solving one problem at a time prevents logic drift.
- Modular Design Localizing the "blast radius" of AI changes.
- Tight Loops Rapid iteration with constant code review.
The Pilot's Correction
Corrective Protocol
// Corrected Code (Optimized) public List<GameObject> enemies = new List<GameObject>(50);
Your Pilot Command
> Use a Coroutine (IEnumerator) to handle timing and delays efficiently.