Re: streaming of a pointer of pointers

From: Paul Russo <russo_at_fnal.gov>
Date: Fri, 22 Aug 2008 17:21:27 -0500


Chiara,

What is allowed are the following:

  // -- A pointer to a varying-length array of objects.
  // MyClass* ary; //[n]
  // -- Or a pointer to a varying-length array of pointers to objects.
  // MyClass** ary; //[n]

  // -- An array of pointers to a varying-length array of objects.
  // MyClass* ary[d]; //[n]

  // -- Or an array of pointers to a varying-length array of pointers to objects.   // MyClass** ary[d]; //[n]

and also the same for basic types, so MyClass could be Float_t as in your example.

If you have:

  Float_t** fHallProbes;

and then write:

  obj.fHallProbes[2][5]

then the compiler translates this to:

  (&obj.fHallProbes[0] + (2 * sizeof(Float_t*))) + (5 * sizeof(Float_t))

So you have an array of pointers to array of Float_t. The [2] indexes into the array of pointers, and the [5] indexes into the pointed at array of Float_t.

This really isn't what you would normally think of as a two-dimensional array, although it works like one, it is not laid out in memory like it would be in FORTRAN. It is a one-dimensional array of pointers, each entry points to a one-dimensional array of Float_t allocated somewhere else.

ROOT does not currently support what you want to do.

However you could do something like this which is supported:

  std::vector<Float_t>* fHallProbes; //[fgknDCSDP_HallProbes]

This would be a pointer to a varying length array of vectors of Float_t, which ROOT can stream.

You would still be able to access it like:

  obj.fHallProbes[2][5]

but the [2] would select a vector<Float_t> from the array, and the [5] would be an index into the vector. The vector itself would naturally know how many entries it had.

You would also have to allocate the data member differently and fill it differently.

Hope this helps!

Chiara Zampolli wrote:
> Hi,
>
> is there any way to stream a pointer of pointers?
> The problem is that I have a member of a class which is a double
> pointer (2D array), and I am not able to stream it. I tried this way:
>
> Float_t** fHallProbes; //[fgknDCSDP_HallProbes][fPoints]
>
> like for single pointers, but it doesn't work... Any idea? I am
> really wondering whether this is possible at all...
>
> Thanks, and cheers,
>
> chiara
>
Received on Sat Aug 23 2008 - 00:21:37 CEST

This archive was generated by hypermail 2.2.0 : Sat Aug 23 2008 - 17:50:01 CEST