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

Home » Public Forums » archive » Re: array of pointers inside a structure
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: array of pointers inside a structure [message #44359] Fri, 10 June 2005 11:21
Robert Moss is currently offline  Robert Moss
Messages: 74
Registered: February 1996
Member
Francois L. wrote:
> I am defining a structure:
>
>> a = 5
>> struct = {A:a, B:intarr(a),C:ptrarr(a)}
>
>
> Further, I want the first element of the array of pointers (C[0]) to be an
> array of 5x5 elements.
>
> How do I create it ?
>

You probably want to use CREATE_STRUCT(), e.g.

a = 5
c = PTRARR( a, /ALLOCATE_HEAP )
*c[ 0 ] = INTARR( 5, 5 ) ;; You did not specify what kind of array here

struct = CREATE_STRUCT( [ 'A', 'B', 'C' ], a, INTARR( a ), c )

Robert Moss
Re: array of pointers inside a structure [message #44360 is a reply to message #44359] Fri, 10 June 2005 11:16 Go to previous message
Antonio Santiago is currently offline  Antonio Santiago
Messages: 201
Registered: February 2004
Senior Member
Francois L. wrote:
> Hello,
>
> I am defining a structure:
>
>> a = 5
>> struct = {A:a, B:intarr(a),C:ptrarr(a)}
>
>
> Further, I want the first element of the array of pointers (C[0]) to be an
> array of 5x5 elements.
>
> How do I create it ?
>
> Thank you,
>
> Fran�ois Leduc
>
>

struct = {A:a, B:intarr(a),C:ptrarr(a)}

'struct' is a STRUCT.
'struct.c' is an array of pointers.
'struct.c[0]' is the first element of the array of pointer.

struct.c[0] = PTR_NEW( INTARR(5,5) ) Now the first element of the
pointer array (a pointer), points to an integer array.

IDL> a=5
IDL> struct = {A:a, B:intarr(a),C:ptrarr(a)}
IDL> struct.c[0] = PTR_NEW( INTARR(5,5) )
IDL> help, struct.c[0]
<Expression> POINTER = <PtrHeapVar2>
IDL> help, *struct.c[0]
<PtrHeapVar2> INT = Array[5, 5]
IDL>

Also you can create a intarr variable and point c[0] to it:

m = INTARR(5,5)
struct.c[0] = PTR_NEW(m)

But remember that PTR_NEW makes a copy of your data into the HEAP
memory. The /NO_COPY keyword creates a copy into HEAP memory and then
undefines the original variable.


--
-----------------------------------------------------
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
-----------------------------------------------------
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: array of pointers inside a structure
Next Topic: Need advice about inheritance

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

Current Time: Wed Oct 08 13:48:57 PDT 2025

Total time taken to generate the page: 0.06259 seconds