.NET Programming Weekly Issue 2 - January 12, 2020

0x00 Will params in C# always cause a new array to be allocated on every call?

  • Yes, a new array is allocated every time.
  • There is of course one special case where “interning” of the kind we discuss here, could be easy to do, and that is for length-zero arrays.

0x01 C# Coroutine WaitForSeconds Garbage Collection tip

  • Unity Scripting Tip.
  • Do not new them every time you need to yield them, but cache the variable and reuse it.

0x02 Is making a struct readonly a breaking change?

  • Before C# 7.2, the compiler will make defensive copies of struct values in cases where the underlying location is considered readonly, because the compiler must assume the worst case which some operation may mutate the content of the struct and hence violates the readonly contract on the field.
  • After C# 7.2, C# added the ability to mark a struct declaration as readonly. It allows the compiler to avoid defensive copies of struct values.

0x03 Nullable must be a readonly struct

  • An issue conversation from dotnet/corefx.
  • Although the title was Nullable <T> must be a readonly struct, it did not do so in the end. Because it’s not so much making Nullable readonly that’s the problem, but rather changing its value field to be readonly (and then the type can’t be readonly).

0x04 How Does HTTPS Work? RSA Encryption Explained

  • This article explains the older RSA encryption method. But still helpful.
  • Explained why https is needed.
  • Symmetric encryption: use the same encryption key on both ends, such as the home wifi.
  • Asymmetric encryption: you’re using two different keys, one to encrypt and one to decrypt.
  • What https does not do.

0x05 Zero allocation code in C# and Unity

  • This article introduces some best practices to avoid heap memory allocation in Unity to avoid the GC of managed code. Of course, these suggestions are useful in other field of C # code programming too.
  • Introduce some useful tools. Such as the Project Auditor maintained by Unity and the Performance Testing Extension for Unity Test Runner1.

  1. Performance Testing Extension for Unity Test Runner ↩︎


Subscribe To Jiadong Chen's Blog

Avatar
Jiadong Chen
Senior Software Developer

HusbandㅣProgrammerㅣAuthorㅣBloggerㅣSpeakerㅣMicrosoft @MVPAward In Developer TechnologiesㅣPreviously @Unity3d ㅣOpinions = my own.

comments powered by Disqus

Related