tags:

views:

53

answers:

2

Hi

This is my simple array declaration

INT64 arr[200000];

Throws error in VC++, but RUNS in C#..

Could you help on this.

Thanks Arun

+3  A: 

Try allocating the array on the heap (using new, or malloc), instead of on the stack.

Alternatively: you can increase the stack size of a thread using the project properties to accomodate that array (it's 200000 * sizeof(INT64) bytes big)

ankon
+2  A: 

In C# you probably have this code:

Int64[] arr = new Int64[200000];

This doesn't allocate the array itself on the stack, only the array reference. Since arrays are reference types in .NET, the array itself lives on the heap, which has wastly more space available than the stack.

In C, the following code:

INT64 arr[200000];

will actually try to allocate the array on the stack, and normally this will fail as most systems doesn't create a stack large enough to hold that much data.

You have multiple options, but the best is probably to allocate it on the heap using the new[] operator instead.

Lasse V. Karlsen