Can't define this matrix

Hi,

I need this matrix:
Double_t matrix[300][100][50];
but root crashes if I add this.

Is there a way to make it work? Do I need to change the data type to something else?

Thank you!

Which version of ROOT? Which platform/compiler? For me it works just fine…

Uhm…
I get this when I launch root:

   ------------------------------------------------------------
  | Welcome to ROOT 6.14/02                http://root.cern.ch |
  |                               (c) 1995-2018, The ROOT Team |
  | Built for linuxx8664gcc                                    |
  | From tags/v6-14-02@v6-14-02, Jul 27 2018, 10:56:25         |
  | Try '.help', '.demo', '.license', '.credits', '.quit'/'.q' |
   ------------------------------------------------------------

I hope it helps. :frowning:

—x---
I tried this simple code:

void a()
{
  Double_t matrix[300][100][50];
  cout << "a" << endl;
}

When I run it, I don’t get that ‘a’ printed on screen and root closes.

So I think the matrix is too large for the stack. Try to allocate it on the heap, or use std::vectors std::vector<std::vector<std::vector<double>>>

300*100*50 == 1500000
times sizeof(Double_t) on your platform. ie: 12Mb.

that’s quite too big for a stack that’s usually 8kb…

Ok, solved using:

  double ***matrix = new double **[xbin];
  for (int i = 0; i < xbin; i++)
  {
    matrix[i] = new double *[ybin];
    for (int j = 0; j < ybin; j++)
      matrix[i][j] = new double[zbin];
  }

Yes, it was due to the stack ‘limit’.
Thank you. :slight_smile:

1 Like

Not sure it wouldn’t be easier and more efficient to allocate the whole thing in one big 1dim chunk and then carve it as a 3dim array…

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.