Re: Dynamic arrays in structs: re-allocation problem [message #70024] |
Tue, 09 March 2010 14:09 |
franzpx125
Messages: 6 Registered: September 2008
|
Junior Member |
|
|
On 9 Mar, 20:50, Ron <oneelkr...@hotmail.com> wrote:
> On Mar 9, 8:59 am, franzpx125 <franzpx...@gmail.com> wrote:
>
>
>
>> Hi!,
>
>> I have troubles with dynamic arrays in structs. The method I use
>> (following N. Wade suggestion) is to define the struct tags in this
>> way:
>
>> static IDL_MEMINT stats_width_dims[IDL_MAX_ARRAY_DIM];
>
>> IDL_STRUCT_TAG_DEF stats_tags[] = {
>> { "WIDTH", stats_width_dims, (void *) IDL_TYP_DOUBLE },
>> { 0 }
>
>> };
>
>> Next I populate the dims arrays which define the size of the dynamic
>> arrays and make a structure with IDL_MakeStruct:
>
>> stats_width_dims[0] = 1;
>> stats_width_dims[1] = stats->counter;
>> s = IDL_MakeStruct("STATS", stats_tags);
>
>> Finally I create a temp structure using IDL_MakeTempStruct:
>
>> tmp_dims[0] = 1;
>> s_data = (char *)IDL_MakeTempStruct(s, 1, tmp_dims, &idl_out_struct,
>> TRUE);
>
>> This temporary structure is returned to IDL after populating it:
>
>> offset = IDL_StructTagInfoByName(s, "WIDTH", IDL_MSG_LONGJMP, NULL);
>> d_tmp_ptr = (double *)(s_data + offset);
>> for ( i = 0; i < stats->Node_Counter; i++)
>> *(d_tmp_ptr++) = stats->width[i];
>
>> return idl_out_struct;
>
>> First time the code is executed, everything works properly. In the
>> second call I'm not able to set the dynamic array with the new
>> dimension and, obviously, if the new dimension is greater than the
>> previous one IDL crashes. I think that the code:
>
>> stats_width_dims[0] = 1;
>> stats_width_dims[1] = stats->counter;
>> s = IDL_MakeStruct("STATS", stats_tags);
>
>> may not be used for updating an existing struct but just for creating
>> a new one. I'm not able to find a valid solution... any suggestion?
>
>> Thanks,
>> F. Brun
>
> What happens if you replace the IDL_MakeStruct() call with,
>
> s = IDL_MakeStruct(NULL, stats_tags);
>
> to create an anonymous structure? It might be that IDL is holding on
> to something since you gave it the name "STATS".
>
> Ron
It works! Thanks a lot.
F. Brun
|
|
|
Re: Dynamic arrays in structs: re-allocation problem [message #70025 is a reply to message #70024] |
Tue, 09 March 2010 11:50  |
rtk
Messages: 22 Registered: September 2008
|
Junior Member |
|
|
On Mar 9, 8:59 am, franzpx125 <franzpx...@gmail.com> wrote:
> Hi!,
>
> I have troubles with dynamic arrays in structs. The method I use
> (following N. Wade suggestion) is to define the struct tags in this
> way:
>
> static IDL_MEMINT stats_width_dims[IDL_MAX_ARRAY_DIM];
>
> IDL_STRUCT_TAG_DEF stats_tags[] = {
> { "WIDTH", stats_width_dims, (void *) IDL_TYP_DOUBLE },
> { 0 }
>
> };
>
> Next I populate the dims arrays which define the size of the dynamic
> arrays and make a structure with IDL_MakeStruct:
>
> stats_width_dims[0] = 1;
> stats_width_dims[1] = stats->counter;
> s = IDL_MakeStruct("STATS", stats_tags);
>
> Finally I create a temp structure using IDL_MakeTempStruct:
>
> tmp_dims[0] = 1;
> s_data = (char *)IDL_MakeTempStruct(s, 1, tmp_dims, &idl_out_struct,
> TRUE);
>
> This temporary structure is returned to IDL after populating it:
>
> offset = IDL_StructTagInfoByName(s, "WIDTH", IDL_MSG_LONGJMP, NULL);
> d_tmp_ptr = (double *)(s_data + offset);
> for ( i = 0; i < stats->Node_Counter; i++)
> *(d_tmp_ptr++) = stats->width[i];
>
> return idl_out_struct;
>
> First time the code is executed, everything works properly. In the
> second call I'm not able to set the dynamic array with the new
> dimension and, obviously, if the new dimension is greater than the
> previous one IDL crashes. I think that the code:
>
> stats_width_dims[0] = 1;
> stats_width_dims[1] = stats->counter;
> s = IDL_MakeStruct("STATS", stats_tags);
>
> may not be used for updating an existing struct but just for creating
> a new one. I'm not able to find a valid solution... any suggestion?
>
> Thanks,
> F. Brun
What happens if you replace the IDL_MakeStruct() call with,
s = IDL_MakeStruct(NULL, stats_tags);
to create an anonymous structure? It might be that IDL is holding on
to something since you gave it the name "STATS".
Ron
|
|
|