baobao
10/9/2018 - 9:08 AM

ReadOnlyCollection変換負荷確認

ReadOnlyCollection変換負荷確認

using System.Collections.Generic;
using System.Collections.ObjectModel;
using UnityEngine;
using UnityEngine.Profiling;

public class ReadOnlyCollectionTest : MonoBehaviour
{
    [SerializeField]
    private int count = 10;

    void Update()
    {
        Profiler.BeginSample("Alloc List");
        List<Foo> list = new List<Foo>(count);
        Profiler.EndSample();

        Profiler.BeginSample("Convert ReadOnlyCollection");
        var readonlyList = new ReadOnlyCollection<Foo>(list);
        Profiler.EndSample();
    }

    class Foo
    {
    }
}