BBC BASIC for Windows
« Arrays of Structures, Plus... »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 11:46pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Arrays of Structures, Plus...  (Read 1167 times)
Matt
Developer

member is offline

Avatar




PM

Gender: Male
Posts: 210
xx 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
User IP Logged

rtr2
Guest
xx 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.
User IP Logged

Matt
Developer

member is offline

Avatar




PM

Gender: Male
Posts: 210
xx 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
User IP Logged

rtr2
Guest
xx 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%
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.
« Last Edit: Nov 9th, 2014, 4:02pm by rtr2 » User IP Logged

Matt
Developer

member is offline

Avatar




PM

Gender: Male
Posts: 210
xx 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 » User IP Logged

rtr2
Guest
xx Re: Arrays of Structures, Plus...
« Reply #5 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.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls