Re: What is the maximum acceptable size of an array?

From: Victor Perevoztchikov <perev_at_bnl.gov>
Date: Tue, 10 Jul 2007 12:48:47 -0400


>And why does it not happen in programs compiled with gcc/g++? But you told just opposite:

>This macro runs without errors when compiled (.L toto.C+) with "#define MAX >1972432" and exits root without any message if compiled with "#define MAX >1972433":

So if compiled version does not work, it is related to stack size. But if non compiled version does not work, then it is not clear. There is no stack in ROOT. Victor

Victor M. Perevoztchikov perev_at_bnl.gov Brookhaven National Laboratory MS 510A PO Box 5000 Upton NY 11973-5000 tel office : 631-344-7894; fax 631-344-4206;

  And why does it not happen in programs compiled with gcc/g++?   What's the exact stack size of ROOT?

  I used static allocation on purpose since it usually causes less problems than dynamic allocation.   I guess I was wrong. ^^'

  On 7/9/07, Victor Perevoztchikov <perev_at_bnl.gov> wrote:     Hi John,
    sure it is related to stack size. When it is not compiled, then this array created by new.     If you will do instead of
      char a[MAX];
    char *a = new char[MAX];
    and at the end delete [] a
    it will work allways correctly
    Victor

     Victor M. Perevoztchikov perev_at_bnl.gov     Brookhaven National Laboratory MS 510A PO Box 5000 Upton NY 11973-5000     tel office : 631-344-7894; fax 631-344-4206;

      I've encountered a strange problem in one of my macros. I managed to reduce it to an array size problem.

      This macro runs without errors when compiled (.L toto.C+) with "#define MAX 1972432" and exits root without any message if compiled with "#define MAX 1972433":

//includes
#include <iostream> using namespace std;
//OK
#define MAX 1972432
//not OK
//#define MAX 1972433

//main function
int toto() { char a[MAX]; cout<<"MAX="<<MAX<<endl; cout<<"total size="<<MAX*sizeof(char)<<" bytes"<<endl; cout<<"total size="<<(float)MAX*(float)sizeof(char)/1024.<<" Kilobytes"<<endl; cout<<"total size="<<(float)MAX*(float)sizeof(char)/(1024.*1024.)<<" Megabytes"<<endl; cout<<"total size="<<MAX*sizeof(char)*8<<" bits"<<endl; return(0); } You might have to change the limit values of MAX to see this problem on your PC. I noticed that it's quite random sometimes. Sometimes it worked with 1972432 and sometimes not. I also recommend quitting and restarting ROOT after each test because it seems to always work if you stay in the ROOT shell even after recompiling. Other tests I made: This macro runs without error when not compiled (.x toto2.C):
//includes
#include <iostream> using namespace std;
//OK
#define MAX 10000000
//not OK
//#define MAX 1972433

//main function
int toto2() { char a[MAX]; cout<<"MAX="<<MAX<<endl; cout<<"total size="<<MAX*sizeof(char)<<" bytes"<<endl; cout<<"total size="<<(float)MAX*(float)sizeof(char)/1024.<<" Kilobytes"<<endl; cout<<"total size="<<(float)MAX*(float)sizeof(char)/(1024.*1024.)<<" Megabytes"<<endl; cout<<"total size="<<MAX*sizeof(char)*8<<" bits"<<endl; return(0); } This C++ program compiles and runs without error:
//includes
#include <iostream> using namespace std;
//OK
#define MAX 10000000
//not OK
//#define MAX 1972433

//main function
int main() { char a[MAX]; cout<<"MAX="<<MAX<<endl; cout<<"total size="<<MAX*sizeof(char)<<" bytes"<<endl; cout<<"total size="<<(float)MAX*(float)sizeof(char)/1024.<<" Kilobytes"<<endl; cout<<"total size="<<(float)MAX*(float)sizeof(char)/(1024.*1024.)<<" Megabytes"<<endl; cout<<"total size="<<MAX*sizeof(char)*8<<" bits"<<endl; return(0); } So, is there any rational explanation to this? Should I use TCloneArrays or TNtuples instead?
Received on Tue Jul 10 2007 - 18:48:59 CEST

This archive was generated by hypermail 2.2.0 : Wed Jul 11 2007 - 11:50:02 CEST