MeasureSize.cs

Get the Amount of Available Memory for Allocation

using System;
public class MeasureSize<T>
{
    private const    int   NumberOfInstances = 10000;
    private readonly T[][] _memArray;
    public MeasureSize()
    {
        _memArray = new T[NumberOfInstances][];
    }
    public long GetByteSize()
    {
        var oldSize = GC.GetTotalMemory(false);
        for (var i = 0; i < NumberOfInstances; i++)
            _memArray[i] = new T[1];
        var newSize = GC.GetTotalMemory(false);
        return (newSize - oldSize) / NumberOfInstances;
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *