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

168
Visualizações
Why does roslyn wrap objects in structures when put in arrays?

While reading through the source code of Roslyn on GitHub, I noticed the much used ObjectPool<T> class. It is used to reduce memory overhead.

Internally it uses an array to store the pooled objects. What I don't understand is why it uses a private struct called Element containing a single field of type T as array element, instead of just using T.

Is this out of concern for performance? Memory overhead?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

It may be for performance reasons. See this article by Jon Skeet.

To summarize, value type arrays are invariant in C#, which means the runtime can avoid doing a compatibility check when storing items in the array. In the article, Mr. Skeet uses a wrapper structure similar to the one you described and shows an improvement in write performance to the array.

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