Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

957
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda