comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: pointer of pointer
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: pointer of pointer [message #48032] Thu, 23 March 2006 00:15
Antonio Santiago is currently offline  Antonio Santiago
Messages: 201
Registered: February 2004
Senior Member
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
-----------------------------------------------------
Re: pointer of pointer [message #48037 is a reply to message #48032] Wed, 22 March 2006 15:07 Go to previous message
steve is currently offline  steve
Messages: 19
Registered: March 1991
Junior Member
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
are slow. More information on pointers can be found at
http://www.dfanning.com/misc_tips/pointers.html

Hope this helps,
Steve
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: extracting numbers
Next Topic: SVD for 3D

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Fri Oct 10 13:12:23 PDT 2025

Total time taken to generate the page: 0.64159 seconds