Array size limited in ROOT on Windows 7

I am curious if there is a way to expand the allowed size of an array when using ROOT on Windows 7.

For example:

#include <Riostream.h>
#define UpperLimit 238800

void test ( )
{
Float_t x [ UpperLimit ] ;
for ( Int_t i = 0 ; i < UpperLimit ; i++ ) x[i] = (float) i ;
cout << " done " << endl ;
}

This macro will fail if it is compiled on Windows 7. It will work when run as a macro without compiling it … but it is incompatible with the compiler (via the command >.x test.C++).

I have tried two different binaries (5.34, VC++10 and VC++12) from the download page and they both exhibit the same behavior. However this does not happen on a Scientific Linux machine. For SL the upper limit on an array appears to have no limit except for the maximum size of the integer used to set the index of the array.

Bottom line: I suspect it is some sort of compiler setting that was set when the binaries were compiled for Windows 7. Can this be overridden or does the binary have to recompiled? If so, with which flags set?

Thoughts or comments?

Cheers,
Jim

Hi Jim,

How does it fail? What do you mean by “incompatible with the compiler”?

[quote=“jhthomas”]I have tried two different binaries (5.34, VC++10 and VC++12)[/quote]You have to make sure to use a ROOT binary built with the EXACT SAME VERSION than your version of Visual Studio, otherwise it will not work

Note you can compile this code:[code]#include “RTypes.h”
#include “Riostream.h”
#define UpperLimit 238800

int main(int argc, char** argv)
{
Float_t x [ UpperLimit ] ;
for ( Int_t i = 0 ; i < UpperLimit ; i++ ) x[i] = (float) i ;
cout << UpperLimit << " done " << endl;
return 0;
}[/code]
using the Microsoft compiler (assuming your file is named array_size.cxx):

cl -nologo -DWIN32 -W3 -D_WINDOWS -Z7 -arch:SSE2 -MD -GR -EHsc array_size.cxx -I %ROOTSYS%\include -FIw32pragma.h /link -debug -LIBPATH:%ROOTSYS%\lib libCore.lib

Now, back to the real issue (which has nothing to do with ROOT BTW).
You are using the stack to allocate the array, and the stack size is limited. So to solve your problem, you have two solutions:
[ul][li] allocate the array in the heap, where you have much more available memory, for example:

Float_t *x = new Float_t[UpperLimit]; for ( Int_t i = 0 ; i < UpperLimit ; i++ ) x[i] = (float) i ; cout << UpperLimit << " done " << endl ; delete [] x; [/li]
[li] increase the stack size. See the compiler option and the linker option to see how increase the stack size when building your application.[/li][/ul]
Cheers, Bertrand.

Dear Bertrand,

Stack versus heap is the answer.

Thank you.

Cheers,
Jim