Author |
Topic: Arrays of Structures, Plus... (Read 1166 times) |
|
Matt
Developer
member is offline


Gender: 
Posts: 210
|
 |
Arrays of Structures, Plus...
« Thread started on: Nov 7th, 2014, 07:17am » |
|
Hi,
I'm using arrays of structures in one of my programs; the help is quite clear on how to dimension and use them. However, there is a slight variation of the structure that I'm not quite clear on.
I need an array of structures but with single header values as well. This is how I've set it out at the moment:
DIM ProtoStruct{ One%, Two%, Three$ } DIM Struct{(10)} = ProtoStruct{} DIM Struct{ Header1$, Header2% }
This seems to work, and I'm assuming that the two structure with the same name work as they would with an array and simple variable with identical names. But is there a way of combining the two together, such as:
DIM ProtoStruct{ One%, Two%, Three$ } DIM Struct{Header1$, Header2%, (10) = ProtoStruct{} }
Although it works fine as it is, combining the two would make it 'neater'.
Matt
|
|
Logged
|
|
|
|
rtr2
Guest
|
 |
Re: Arrays of Structures, Plus...
« Reply #1 on: Nov 7th, 2014, 08:13am » |
|
on Nov 7th, 2014, 07:17am, Matt wrote:But is there a way of combining the two together |
|
No. BBC BASIC doesn't support sub-structure-arrays. I know it's not really what you wanted, but this is what I would probably do in your situation:
Code: DIM Struct{Header1$, Header2%, One%(10), Two%(10), Three$(10)} Richard.
|
|
Logged
|
|
|
|
Matt
Developer
member is offline


Gender: 
Posts: 210
|
 |
Re: Arrays of Structures, Plus...
« Reply #2 on: Nov 9th, 2014, 1:58pm » |
|
on Nov 7th, 2014, 08:13am, g4bau wrote:I know it's not really what you wanted, but this is what I would probably do in your situation |
|
Thanks. I have used something like this in the past - and again, it works fine. I didn't know if there was a difference in the workings of the two, and a good reason for using one over the other - for instance, a speed difference. A rudimentory test suggested around a 2% increase in speed when using Struct{(n)}.var% over Struct.var%(n).
Matt
|
|
Logged
|
|
|
|
rtr2
Guest
|
 |
Re: Arrays of Structures, Plus...
« Reply #3 on: Nov 9th, 2014, 3:49pm » |
|
on Nov 9th, 2014, 1:58pm, Matt wrote:A rudimentory test suggested around a 2% increase in speed when using Struct{(n)}.var% over Struct.var%(n). |
|
Somewhat surprising. In BB4W v6.beta10:
Platform | Struct.var%(n) | Struct{(n)}.var% | IDE | 128 cs | 130 cs | Compiled | 123 cs | 125 cs | REM!Fast | 96 cs | 98 cs |
But then speed shouldn't really be the deciding factor! And of course much more memory is used by the second option (12 bytes per array element instead of 4).
Richard.
|
« Last Edit: Nov 9th, 2014, 4:02pm by rtr2 » |
Logged
|
|
|
|
Matt
Developer
member is offline


Gender: 
Posts: 210
|
 |
Re: Arrays of Structures, Plus...
« Reply #4 on: Nov 9th, 2014, 8:01pm » |
|
on Nov 9th, 2014, 3:49pm, g4bau wrote:And of course much more memory is used by the second option (12 bytes per array element instead of 4). |
|
That's definitely a more useful thing to know. I didn't occur to me that the difference in memory useage would be that much. The program uses thousands rather than ten, so this is worth noting.
Thanks
Matt
p.s. is the REM!Fast a v6 directive? I can't find it in the help.
|
« Last Edit: Nov 9th, 2014, 8:05pm by Matt » |
Logged
|
|
|
|
|