Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

956
Vistas
C# How Can I Sort A List without Generating Any Garbage at All (Unity3d)

The method used by List.Sort ends up using Array.Sort which generates 2 bytes of garbage even if you pass in an instance for IComparer. I need to sort many lists every frame in Unity3d so I need an algorithm that will not create a single byte of garbage if possible. Stack allocation for temporary variables should be fine.

Unity Profiler Pic

if (comparer == null)
    comparer = (IComparer<T>)Comparer<T>.Default;
if (BinaryCompatibility.TargetsAtLeast_Desktop_V4_5)
    ArraySortHelper<T>.IntrospectiveSort(keys, index, length, comparer);
else
    ArraySortHelper<T>.DepthLimitedQuickSort(keys, index, length + index - 1, comparer, 32);
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Check out this library in this github repo. I found this in bottom in this article which is about how LINQ affects GC and which LINQ function is safe to use on every frame. This library is written especially for unity and as author says this library is

A no-GC version of C#'s IEnumerator and LINQ

There is sort method which implements quickSort algorithms and does not produce garbage. To be honest I don't fully tested it yet, but as much as I used that it works finely.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda