Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

166
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!