Data Structures

Abhishek Smith

Abhishek Smith

Building Outscal | Land Jobs in the gaming industry | EA, Epic Games, TCS, | CMU, IIT K

Basic Collections (Managed)

  • Arrays: Fast, fixed-size, perfect for known collections
  • List<T>: Flexible size but watch for GC spikes
  • Dictionary<K,V>: Lightning-fast lookups, memory hungry

Common Issues

  • All generate garbage collection
  • Can cause memory fragmentation
  • Performance degrades with large datasets

Specialized Unity Collections

  • SerializedDictionary: Editor-friendly, great for config data
  • ObservableList: Perfect for UI-bound collections
  • CircularBuffer: Ideal for command history, rolling stats
  • ObjectPool: Must-have for spawning systems

Issues:

  • More complex than standard collections
  • Higher memory overhead
  • Require careful implementation

High Performance (Native)

  • NativeArray: Burst-compatible, no GC overhead
  • NativeList: Dynamic size without the GC cost
  • NativeHashMap: High-performance lookups in Jobs

Issues:

  • Must manually manage memory (Dispose)
  • Not visible in Inspector
  • More complex to debug

Pro Tips:

  • Always profile before optimizing
  • Start simple (List/Array) before going native
  • Use ObjectPools for frequently spawned objects
  • Don't forget to Dispose() native collections!

Common Pitfalls:

  • Using List<T> in performance-critical loops
  • Forgetting to pre-allocate capacities
  • Missing Dispose() calls on Native collections
  • Over-engineering with complex structures too early

Show More