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

From: John Zoidberg <zohn.joidberg_at_gmail.com>
Date: Mon, 9 Jul 2007 19:02:15 +0200


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;
>
> ----- Original Message -----
> *From:* John Zoidberg <zohn.joidberg_at_gmail.com>
> *To:* roottalk_at_root.cern.ch
> *Sent:* Monday, July 09, 2007 12:02 PM
> *Subject:* [ROOT] What is the maximum acceptable size of an array?
>
> 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 Mon Jul 09 2007 - 19:02:23 CEST

This archive was generated by hypermail 2.2.0 : Tue Jul 10 2007 - 23:50:02 CEST