Deleting arrays

Hello all,
im using ROOT for a short time now and i have this problem:
for storing data, i need a multidimensional array, something like
array[x][y][z].
After initializing, i fill the array in a loop, and then do some computation.
At the end, i need to delete this array, or somehow reset it. How can i do this? I tried delete and delete[]… Is there a kind of ROOT array i could use?

Thanks,
Daniel

[quote]Hello all,
im using ROOT for a short time now and i have this problem:
for storing data, i need a multidimensional array, something like
array[x][y][z].
After initializing, i fill the array in a loop, and then do some computation.
At the end, i need to delete this array, or somehow reset it. How can i do this? I tried delete and delete[]… Is there a kind of ROOT array i could use?
[/quote]

You should show your code, your question is too general.

Is it a local variable? Do you know the dimensions of your array at “compile time”? If yes, and these dimensions are not too big, if sizeof(ArrayElementType) is not too big - you can use built-in arrays - so they will be allocated on a stack (if it’s a local variable) - this allocation is fast and you do not need to clean-up.

int array[n][k][m].

If you cannot use built-in arrays, you’d better use std::vector. And not ugly vector of vector of vector … - you can simply do this:

//“3D” array.

std::vector array(xSize * ySize * zSize);

Now, you only need to know, how to access element [i][j][k]:

array[i * ySize * zSize + j * zSize + k] = 10;

So, no manual memory management, all is done by C++ standard library for you, and you code is smaller, cleaner, safer.

Thanks! It was a local variable/array. The histogram were very similar so i didnt know if it was true what i had seen.
Your answer helped a lot!