Skip to main content
syntax coloring
Source Link
Victor Stafusa
  • 8.8k
  • 5
  • 40
  • 61
public unsafe struct Godzilla
{
    public const int Size = 40900;
    fixed double data[Size];
    public Godzilla(double init)
    {
        fixed(double* ptr=data)
        {
            for(int i=0; i<Size; i++)
            {
                ptr[i]= init;
            }
        }
    }

    public void Add(Godzilla other)
    {
        fixed(double* ptr=data)
        {
            for(int i=0; i<Size; i++)
            {
                ptr[i]+=other.data[i];
            }
        }
    }
}

class Program
{
    static void Main(string[] args)
    {
        Godzilla A=new Godzilla(1.0);
        Godzilla B=new Godzilla(2.0);
        A.Add(B);
    }
}
public unsafe struct Godzilla
{
    public const int Size = 40900;
    fixed double data[Size];
    public Godzilla(double init)
    {
        fixed(double* ptr=data)
        {
            for(int i=0; i<Size; i++)
            {
                ptr[i]= init;
            }
        }
    }

    public void Add(Godzilla other)
    {
        fixed(double* ptr=data)
        {
            for(int i=0; i<Size; i++)
            {
                ptr[i]+=other.data[i];
            }
        }
    }
}

class Program
{
    static void Main(string[] args)
    {
        Godzilla A=new Godzilla(1.0);
        Godzilla B=new Godzilla(2.0);
        A.Add(B);
    }
}
public unsafe struct Godzilla
{
    public const int Size = 40900;
    fixed double data[Size];
    public Godzilla(double init)
    {
        fixed(double* ptr=data)
        {
            for(int i=0; i<Size; i++)
            {
                ptr[i]= init;
            }
        }
    }

    public void Add(Godzilla other)
    {
        fixed(double* ptr=data)
        {
            for(int i=0; i<Size; i++)
            {
                ptr[i]+=other.data[i];
            }
        }
    }
}

class Program
{
    static void Main(string[] args)
    {
        Godzilla A=new Godzilla(1.0);
        Godzilla B=new Godzilla(2.0);
        A.Add(B);
    }
}
public unsafe struct Godzilla
{
    public const int Size = 40900;
    fixed double data[Size];
    public Godzilla(double init)
    {
        fixed(double* ptr=data)
        {
            for(int i=0; i<Size; i++)
            {
                ptr[i]= init;
            }
        }
    }

    public void Add(Godzilla other)
    {
        fixed(double* ptr=data)
        {
            for(int i=0; i<Size; i++)
            {
                ptr[i]+=other.data[i];
            }
        }
    }
}

class Program
{
    static void Main(string[] args)
    {
        Godzilla A=new Godzilla(1.0);
        Godzilla B=new Godzilla(2.0);
        A.Add(B);
    }
}
deleted 1 characters in body
Source Link

C#

Using fixed arrays in struct, without recursion.and loading (Compile x86 or AnyCPU)struct into the stack for an operation.

public unsafe struct Godzilla
{
    public const int Size = 40900;
    fixed double data[Size];
    public Godzilla(double init)
    {
        fixed(double* ptr=data)
        {
            for(int i=0; i<Size; i++)
            {
                ptr[i]= init;
            }
        }
    }

    public void Add(Godzilla other)
    {
        fixed(double* ptr=data)
        {
            for(int i=0; i<Size; i++)
            {
                ptr[i]+=other.data[i];
            }
        }
    }
}

class Program
{
    static void Main(string[] args)
    {
        Godzilla A=new Godzilla(1.0);
        Godzilla B=new Godzilla(2.0);
        A.Add(B);
    }
}

It tries to load all the values on the stack and fails. Each struct is 8×40900 = 327,200 bytes long and when two of them get loaded into the stack it pukes.

SO

C#

Using fixed arrays in struct, without recursion. (Compile x86 or AnyCPU).

public unsafe struct Godzilla
{
    public const int Size = 40900;
    fixed double data[Size];
    public Godzilla(double init)
    {
        fixed(double* ptr=data)
        {
            for(int i=0; i<Size; i++)
            {
                ptr[i]= init;
            }
        }
    }

    public void Add(Godzilla other)
    {
        fixed(double* ptr=data)
        {
            for(int i=0; i<Size; i++)
            {
                ptr[i]+=other.data[i];
            }
        }
    }
}

class Program
{
    static void Main(string[] args)
    {
        Godzilla A=new Godzilla(1.0);
        Godzilla B=new Godzilla(2.0);
        A.Add(B);
    }
}

It tries to load all the values on the stack and fails. Each struct is 8×40900 = 327,200 bytes long and when two of them get loaded into the stack it pukes.

SO

C#

Using fixed arrays and loading struct into the stack for an operation.

public unsafe struct Godzilla
{
    public const int Size = 40900;
    fixed double data[Size];
    public Godzilla(double init)
    {
        fixed(double* ptr=data)
        {
            for(int i=0; i<Size; i++)
            {
                ptr[i]= init;
            }
        }
    }

    public void Add(Godzilla other)
    {
        fixed(double* ptr=data)
        {
            for(int i=0; i<Size; i++)
            {
                ptr[i]+=other.data[i];
            }
        }
    }
}

class Program
{
    static void Main(string[] args)
    {
        Godzilla A=new Godzilla(1.0);
        Godzilla B=new Godzilla(2.0);
        A.Add(B);
    }
}

It tries to load all the values on the stack and fails. Each struct is 8×40900 = 327,200 bytes long and when two of them get loaded into the stack it pukes.

SO

added 101 characters in body
Source Link

C#

Using fixed arrays in struct, without recursion. (Compile x86 or AnyCPU).

public unsafe struct Godzilla
{
    public const int Size = 40900;
    fixed double data[Size];
    public Godzilla(double init)
    {
        fixed(double* ptr=data)
        {
            for(int i=0; i<Size; i++)
            {
                ptr[i]= init;
            }
        }
    }

    public void Add(Godzilla other)
    {
        fixed(double* ptr=data)
        {
            for(int i=0; i<Size; i++)
            {
                ptr[i]+=other.data[i];
            }
        }
    }
}

class Program
{
    static void Main(string[] args)
    {
        Godzilla A=new Godzilla(1.0);
        Godzilla B=new Godzilla(2.0);
        A.Add(B);
    }
}

It tries to load all the values on the stack and fails. Each struct is 8×40900 = 327,200 bytes long and when two of them get loaded into the stack it pukes.

SO

C#

Using fixed arrays in struct, without recursion. (Compile x86 or AnyCPU).

public unsafe struct Godzilla
{
    public const int Size = 40900;
    fixed double data[Size];
    public Godzilla(double init)
    {
        fixed(double* ptr=data)
        {
            for(int i=0; i<Size; i++)
            {
                ptr[i]= init;
            }
        }
    }

    public void Add(Godzilla other)
    {
        fixed(double* ptr=data)
        {
            for(int i=0; i<Size; i++)
            {
                ptr[i]+=other.data[i];
            }
        }
    }
}

class Program
{
    static void Main(string[] args)
    {
        Godzilla A=new Godzilla(1.0);
        Godzilla B=new Godzilla(2.0);
        A.Add(B);
    }
}

It tries to load all the values on the stack and fails.

SO

C#

Using fixed arrays in struct, without recursion. (Compile x86 or AnyCPU).

public unsafe struct Godzilla
{
    public const int Size = 40900;
    fixed double data[Size];
    public Godzilla(double init)
    {
        fixed(double* ptr=data)
        {
            for(int i=0; i<Size; i++)
            {
                ptr[i]= init;
            }
        }
    }

    public void Add(Godzilla other)
    {
        fixed(double* ptr=data)
        {
            for(int i=0; i<Size; i++)
            {
                ptr[i]+=other.data[i];
            }
        }
    }
}

class Program
{
    static void Main(string[] args)
    {
        Godzilla A=new Godzilla(1.0);
        Godzilla B=new Godzilla(2.0);
        A.Add(B);
    }
}

It tries to load all the values on the stack and fails. Each struct is 8×40900 = 327,200 bytes long and when two of them get loaded into the stack it pukes.

SO

Source Link
Loading