f

#### pointer of pointer

```Hello,

I have to make an array which size of the lines depends of the line.
I am sure I am not clear so here is an exemple of what I mean :

a is an array of n lines
each line contain a different number of elements

I have tried to implement something like this

a=PTRARR(n)
FOR i=0,n-1 DO BEGIN
a(i)=Ptr_New
ENDFOR

First I am not sure it is the best way to compute this,
second if yes I don't how to implemente the value of the "a(i,j)"
element.

If somebody can help me...
Best regards,

Claire

```
 0
3/22/2006 5:37:21 PM
comp.lang.idl-pvwave 12260 articles. 4 followers.

2 Replies
682 Views

Similar Articles

[PageSpeed] 54

```Hey Claire,

If you absolutely must have each element of "a" be an array of a
different length the path you started down will work.

You can allocate the different lines like this:

a = PtrArr(n)
a[0] = Ptr_New(IntArr(lineSize))

After you have allocated the space, you can set an element like this:

(*a[n])[lineElement] = 0

Just keep in mind that doing this is going to be slow because pointers
http://www.dfanning.com/misc_tips/pointers.html

Hope this helps,
Steve

```
 0
3/22/2006 11:07:34 PM
```claire.maraldi@gmail.com wrote:
> Hello,
>
> I have to make an array which size of the lines depends of the line.
> I am sure I am not clear so here is an exemple of what I mean :
>
> a is an array of n lines
> each line contain a different number of elements
>
> I have tried to implement something like this
>
> a=PTRARR(n)
> FOR i=0,n-1 DO BEGIN
>    a(i)=Ptr_New
> ENDFOR
>
> First I am not sure it is the best way to compute this,
> second if yes I don't how to implemente the value of the "a(i,j)"
> element.
>

As you point, you can do:

n = 10

a = PTRARR(n)

;;Create an array of pointers that points to different byte array
;;sizes.
FOR i=0, n-1 DO BEGIN
a[i] = PTR_NEW( BINDGEN(n*i+10) )
ENDFOR

Ok, now to get a(i,j) take a look at this:

IDL> help, a
A               POINTER   = Array[10]
IDL> help, a[4]
<Expression>    POINTER   = <PtrHeapVar25>
IDL> help, *a[4]
<PtrHeapVar25>  BYTE      = Array[50]
IDL> help, (*a[4])[10]
<Expression>    BYTE      =   10

The content of fourth position (*a[4]) of the pointer array is an array
of 50 positions. In a general way:

value = (*a[i])[j]

> If somebody can help me...
> Best regards,
>
> Claire
>

I dont' know if this way is as fast as using a "normal" array, that is,
I suposse pointers penalizes on acces time.

--
-----------------------------------------------------
Antonio Santiago P�rez
( email: santiago<<at>>grahi.upc.edu       )
(   www: http://www.grahi.upc.edu/santiago )
(   www: http://asantiago.blogsite.org     )
-----------------------------------------------------
GRAHI - Grup de Recerca Aplicada en Hidrometeorologia
Universitat Polit�cnica de Catalunya
-----------------------------------------------------
```
 0
santiago5456 (105)
3/23/2006 8:15:58 AM