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;
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;
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;
return(0);
}
So, is there any rational explanation to this? Should I use TCloneArrays or TNtuples instead? Received on Mon Jul 09 2007 - 18:02:50 CEST
This archive was generated by hypermail 2.2.0 : Mon Jul 09 2007 - 23:50:02 CEST