[Mono-dev] Crazy StackAlloc

Jambunathan K kjambunathan.devel at gmail.com
Thu May 7 09:52:23 EDT 2009


I am surprised that there is a Number Overflow exception reported in
my earlier post.
The earlier run had size set to 1 * 1024 * 1024. Can someone explain this?

Anyways here is a run with size set to 24 * 1024 * 1024.

I apologize for being incoherent and inarticulate. Yet I hope my post
is considered.

kjambunathan at kjambunathan-desktop:~/src/ws/mono-2.4/mono$ cat
StackAllocCrazy.cs && mcs /unsafe StackAllocCrazy.cs && mono
StackAllocCrazy.exe
using System;

class T
{

        public unsafe static void Main ()
        {
        int size = 24 * 1024 * 1024;

        while (size != 0) {
                Console.WriteLine ("Trying " + size + " bytes ...");

                try {
                        long *buf = stackalloc long[size];

                        for (int i = 0; i < size; ++i)
                                buf[i] = 0;

                } catch (Exception e) {
                        Console.WriteLine ("Caught " + e);
                        size /= 2;
                        continue;
                }

                Console.WriteLine ("Can stackalloc " + size + " longs");
                break;
        }
        }
}
Trying 25165824 bytes ...
Stack overflow in unmanaged: IP: 0x8108cd2, fault addr: 0xbf7bfff0
Stack overflow in unmanaged: IP: 0x8073bc8, fault addr: 0xbf7bff1c
Stack overflow in unmanaged: IP: 0x8073bc8, fault addr: 0xbf7bfeac
Stack overflow in unmanaged: IP: 0xb7eed44c, fault addr: 0xbf7bffec
Stack overflow in unmanaged: IP: 0x8073bc8, fault addr: 0xbf7bfebc
Stack overflow in unmanaged: IP: 0xb7dba573, fault addr: 0xbf7bee58
Stack overflow in unmanaged: IP: 0x8073bc8, fault addr: 0xbf7bfecc
Stack overflow in unmanaged: IP: 0x8073bc8, fault addr: 0xbf7bfecc
Stack overflow in unmanaged: IP: 0x8073bc8, fault addr: 0xbf7bfe9c
Stack overflow in unmanaged: IP: 0xb7de3944, fault addr: 0xbf7bffe8
Stack overflow in unmanaged: IP: 0x8073bc8, fault addr: 0xbf7bfeac
Stack overflow in unmanaged: IP: 0x81d7f5d, fault addr: 0xbf7bfe7c
Stack overflow in unmanaged: IP: 0x81083ac, fault addr: 0xbf7bffec
Stack overflow in unmanaged: IP: 0x81074fc, fault addr: 0xbf7bfffc
Stack overflow in unmanaged: IP: 0xb7dba573, fault addr: 0xbf7bee38
Stack overflow in unmanaged: IP: 0x8073bc8, fault addr: 0xbf7bfe9c
Stack overflow in unmanaged: IP: 0xb7dba573, fault addr: 0xbf7bee38
Stack overflow in unmanaged: IP: 0x8073bc8, fault addr: 0xbf7bfecc
Stack overflow in unmanaged: IP: 0xb7de58dc, fault addr: 0xbf7bfff8
Stack overflow in unmanaged: IP: 0xb7dba573, fault addr: 0xbf7bfe0c

Unhandled Exception: System.StackOverflowException: The requested
operation caused a stack overflow.
  at (wrapper managed-to-native) System.MonoType:getFullName (bool,bool)
  at System.MonoType.ToString () [0x00000]
  at System.Exception.get_ClassName () [0x00000]
  at System.Exception.ToString () [0x00000]


More information about the Mono-devel-list mailing list