BBC BASIC for Windows
Programming >> BBC BASIC language >> Arrays of Structures, Plus... http://bb4w.conforums.com/index.cgi?board=language&action=display&num=1415348265 Arrays of Structures, Plus...
Post by Matt 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
Re: Arrays of Structures, Plus...
Post by rtr2 on Nov 7th, 2014, 08:13am
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
Re: Arrays of Structures, Plus...
Post by rtr2 on Nov 9th, 2014, 3:49pm
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. Re: Arrays of Structures, Plus...
Post by Matt on Nov 9th, 2014, 8:01pm
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.
Re: Arrays of Structures, Plus...
Post by rtr2 on Nov 9th, 2014, 9:38pm