예제 #1
0
    public unsafe void UnsafeList_TrimExcess()
    {
        var sizeOf  = UnsafeUtility.SizeOf <int>();
        var alignOf = UnsafeUtility.AlignOf <int>();

        using (var list = new UnsafeList(sizeOf, alignOf, 32, Allocator.Persistent, NativeArrayOptions.ClearMemory))
        {
            var capacity = list.Capacity;

            list.Add(1);
            list.TrimExcess <int>();
            Assert.AreEqual(1, list.Length);
            Assert.AreEqual(1, list.Capacity);

            list.RemoveAtSwapBack <int>(0);
            Assert.AreEqual(list.Length, 0);
            list.TrimExcess <int>();
            Assert.AreEqual(list.Capacity, 0);

            list.Add(1);
            Assert.AreEqual(list.Length, 1);
            Assert.AreNotEqual(list.Capacity, 0);

            list.Clear();
        }
    }
예제 #2
0
    public void UnsafeListT_Performance_Add()
    {
        const int numElements = 16 << 10;

        var list = new UnsafeList <int>(1, Allocator.Persistent, NativeArrayOptions.ClearMemory);

        Measure.Method(() =>
        {
            list.Length = 1;
            list.TrimExcess();

            for (int i = 0; i < numElements; ++i)
            {
                list.Add(i);
            }
        })
        .WarmupCount(100)
        .MeasurementCount(1000)
        .Run();

        list.Dispose();
    }