C# A delegate in is equivalent to a class ( Is not a value type , It's a reference type ),

When it is passed in as a formal parameter  
perhaps   System.Action b = TestB;//TestB It's a method ,
This is called once to generate 112bytes Of gcalloc
So we have to avoid update In this way .

In the same way , We try to avoid using it LINQ sentence , because Linq Statement requires us to pass in a delegate (delegate) Or method name , perhaps lambda expression . that GC And then it came into being .

It's very likely that we LINQ Will be used in sort functions , So it came into being GC It's not a small number .

The game's Caton will follow .

Test code :
List<int> list = new List<int>(); for(int i = 0; i < 100;i++) {
list.Add(UnityEngine.Random.Range(0, int.MaxValue)); } int target = 200; int
resultLinq = 0, resultFor = 0;
UnityEngine.Profiling.Profiler.BeginSample("MY_TEST LINQ"); resultLinq =
list.Find(i => i == target); UnityEngine.Profiling.Profiler.EndSample();
UnityEngine.Profiling.Profiler.BeginSample("MY_TEST FOR"); foreach (var i in
list) { if (i == target) { resultFor = i; } }
UnityEngine.Profiling.Profiler.EndSample();
 

Profiler result : notice gcalloc It came into being

 

Technology
©2019-2020 Toolsou All rights reserved,
One is called “ Asking for the train ” A small village Finally got the train Spring Boot Lesson 16 :SpringBoot Implementation of multithreading with injection class Chrome OS, For programmers and Windows What does it mean ? Internet Marketing JAVA Convert a string to a numeric type I've been drinking soft water for three years ? What is the use of soft water and water softener You don't know ——HarmonyOS Talking about uni-app Page value transfer problem JavaScript Medium Call and ApplySparkSQL Achieve partition overlay write Character recognition technology of vehicle license plate based on Neural Network