Page 1 of 1
Subs vs. Gosubs
Posted: Wed Mar 26, 2003 8:15 am
by Guest
DOS.6.22 & QB.4.5 -- 486 proc.... Is it more efficient in execution speed and/or RAM usage to use Subs in preference to Gosubs or doesn't it really matter??? ... Which of the Open file formats is most efficient or again doesn't it matter???
Re: Subs vs. Gosubs
Posted: Wed Mar 26, 2003 3:30 pm
by frankiebaby
I'm not sure about Subs Or Gosubs. I would imagine you COULD say gosubs are more memory efficient, but QB by defualt passes by pointer, so that doesn't matter, as far as proccessor, same deal, a gosub doesnt require (i don't think) passing any arguements at all. I don't use gosubs much though anyway, I doubt the speed increase would be much, if any.
As far as a more efficient OPEN, i would say binary, but that requires that you always read in the same type of variables, and limit any strings to a set size. Here's the deal. I used OPEN for OUTPUT to save an image for most of the screen, came out to about 37Kb. Using BINARY, 9Kb get the idea? OUTPUT must be comma or space delimited, binary does not.
Re: Subs vs. Gosubs
Posted: Thu Mar 27, 2003 5:24 am
by Dr_Davenstein
I use SUB alot more than GOSUB for the simple reason that they are easier to use.Well, "I think they are".
Umm... Maybe not easier just more convenient!
Passing an argument to a SUB keeps that part of the program in a "room" by itself.It's easier to organize that way, plus you can call it from anywhere.If your in a SUB,
you can't call a GOSUB that's in the main-loop of the program,(besides an on key or on timer call).Well, if you can then I don't know how.I guess we'll see huh?
This is a good example...
Say you want to get a random number between 4 and 8,you would probably do this right?
Rand = 4 + int(rnd * 5)
If you wanted to get a number between 2 and 10 then you would have to write that code over again,ya know?
But with a function...
So what, it's just like a sub!
Function Rand%(small% , big%)
Rand2%= small% + Int(rnd *big% + 1)
Rand%=Rand2%
End Function
Then call it like...
number1%=Rand%(4 , 8)
number2%=Rand%(2 , 10)
If you already knew this stuff then I'm sorry if I wasted your time!
If you did'nt then I hope it helped you.
Re: Subs vs. Gosubs
Posted: Fri Mar 28, 2003 7:04 am
by Guest
FrankieB & Dr-D many thanks for your responses and you guys could never waste my time. :D ... I have however not explained the second part of my question very well (as usual for me - sorry :-[) ... I should have asked which OPEN statement is more efficient. I have habitually used OPEN "I",#1,"C:/filename.ext" ... Is another format more efficient?
Re: Subs vs. Gosubs
Posted: Fri Mar 28, 2003 12:23 pm
by Dr_Davenstein
I don't know about more efficient but, a while back I used BSAVE and BLOAD to save/load the maze DATA on a PAC-MAN clone that I made!
It's all gone now,(I have a new PC and it was experimental code), but it was alot FASTER than anything else I could conjure up! 8)
OOPs... did I post that?
Oh man, did I do it again?!?!?!
Re: Subs vs. Gosubs
Posted: Wed Apr 02, 2003 1:31 pm
by Guest
Regarding GOSUB and DECLARE SUB:
I use GOSUB for very short programs as GOSUBs eat-up main module memory. I tend to use DEC. SUBs for larger programs since they are esentially a Far Call (as in C).
Regarding OPEN:
Here's a direct copy from the QB 4.5 Help regarding that particular syntax:
Syntax 2
OPEN mode2,[#]filenum,file[,reclen]
In the second form of the OPEN syntax, mode2 is a string expression the
first character of which must be one of the following:
Mode Description
O Specifies sequential output mode.
I Specifies sequential input mode.
R Specifies random-access file input/output mode.
B Specifies binary file mode.
A Specifies sequential output mode and sets the file pointer
to the end of the file and the record number to the last
record of the file. A PRINT # or WRITE # statement extends
(appends to) the file.
Note: The second OPEN syntax does not support any of the access and
file-sharing options found in the first syntax and is supported
for compatibility with programs written in earlier versions of
BASIC.
This can be found in the HELP/INDEX/OPEN (file)/DETAILS [at the end of details] in QB 4.5 . I did not see this mentioned in QB 7.1, though.
Hope this helps.
--MiggyD