Re: array of pointers inside a structure [message #44359] |
Fri, 10 June 2005 11:21 |
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  |
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
-----------------------------------------------------
|
|
|