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

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.

Re: Arrays of Structures, Plus...
Post by Matt 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
Re: Arrays of Structures, Plus...
Post by rtr2 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%
IDE128 cs130 cs
Compiled   123 cs125 cs
REM!Fast96 cs98 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

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.
Re: Arrays of Structures, Plus...
Post by rtr2 on Nov 9th, 2014, 9:38pm

on Nov 9th, 2014, 8:01pm, Matt wrote:
p.s. is the REM!Fast a v6 directive? I can't find it in the help.

Yes. The main help docs won't include any v6-specific information unless and until it's released.

http://bb4w.conforums.com/index.cgi?board=general&action=display&num=1395961811&start=6

Richard.