zoukankan      html  css  js  c++  java
  • Understanding the managed heap

    Understanding the managed heap

    1、common problem faced by many Unity developers is the unexpected expansion of the managed heap。

    2、The “managed heap” is a section of memory that is automatically managed by the memory manager of a Project’s scripting runtime (Mono or IL2CPP). 

      managed heap 由 Mono、IL2CPP 的 memory manager 自动管理。

    3、Crucially, Unity’s garbage collection – which uses the Boehm GC algorithm – is non-generational and non-compacting. “Non-generational” means that the GC must sweep through the entire heap when performing a collection pass, and its performance therefore degrades as the heap expands. “Non-compacting” means that objects in memory are not relocated in order to close gaps between objects.

      Unity's garbage collection 不会使用 relocate 来缓解  fragmentation 问题。

    4、if a large object is allocated and there is insufficient contiguous free space to accommodate the object, as illustrated above, the Unity memory manager performs two operations.

      First, if it has not already done so, the garbage collector runs. This attempts to free up enough space to fulfill the allocation request.

      Second, If, after the GC runs, there is still not enough contiguous space to fit the requested amount of memory, the heap must expand. The specific amount that the heap expands is platform-dependent; however, most Unity platforms double the size of the managed heap.

      

    5、 converting an anonymous method to a closure significantly increases the amount of memory required to pass the closure to method receiving it.

      closure 比 anonymous method 消费更多内存。

    List<float> listOfNumbers = createListOfRandomNumbers();
    
    // anonymous method
    listOfNumbers.Sort( (x, y) =>
        (int)x.CompareTo((int)(y/2)) 
    );
    
    
    List<float> listOfNumbers = createListOfRandomNumbers();
    
    int desiredDivisor = getDesiredDivisor();
    // closure
    listOfNumbers.Sort( (x, y) =>
        (int)x.CompareTo((int)(y/desiredDivisor))
    );
    View Code

    6、Dictionaries and enums

      Enum 作为 Dictionary 的 Key时,会导致 boxing。 通过提供 Comparer 即可解决此 Boxing。

    public class MyEnumComparer : IEqualityComparer<MyEnum> 
    {
        public bool Equals(MyEnum x, MyEnum y) {
            return x == y;
        }
        
        public int GetHashCode(MyEnum x) {
            return (int)x;
        }
    }

    7、

    8、

    参考:

    1、https://docs.unity3d.com/Manual/BestPracticeUnderstandingPerformanceInUnity4-1.html

  • 相关阅读:
    二维码生成插件(jquery.qrcode.js)说明文档
    JS&PHP如何实现二维码的生成以及识别(代码)
    【干货】Chrome插件(扩展)开发全攻略 写在前面
    电脑连接并调试手机浏览器的网页
    php操作mysql数据库(增删改查)
    springBoot+springCloud学习笔记
    HttpClient远程调用接口
    fastjson List<> 转Json , Json 转List<>
    连接redis失败,关闭防火墙即可
    复习mybatis框架(一)----映射文件
  • 原文地址:https://www.cnblogs.com/tekkaman/p/10834448.html
Copyright © 2011-2022 走看看