GOSUB instead PROCEDURE barrier ?
Posted: Sat Mar 26, 2005 3:51 am
i am working on a program with a lot of procedures. this would looks like:
As you may see, the CodeB part is in nearly every procedure and this part is ever exactly the same
So i thought about a subroutine to store only the CodeB part and call this subroutine with GOSUB inside a procedure, like:
I know i have to set the variables from the procedures as global to use it in a subroutine too!? But the way to call a subroutine inside a procedure does not works!
So i thought and stored the subroutine code into a new procedure, which works! But this way is very bad for my code, because when calling the main procedure and this is calling a such called sub-procedure, my program runs about factor 100 slower ;( (here an example of the way, that slow down my program)
Is there really no other way like GOSUB, without loosing so much performance? Ok, i could copy the full subroutine (CodeB) and paste it into each Procedure! There are good and bad reasons for this way...
maybe someone can see my problem and have a solution for this problem! Btw, are Gosubs in C/C++/C# or any other languages inside a procedure of function forbidden too? fred?
Code: Select all
Procedure Test1(val1,val2,val3...)
...Code1A - Never the same code...
...Code1B - ThisPart is ever the same...
EndProcedure
Procedure Test2(val1,val2,val3...)
...Code2A - Never the same code...
...Code2B - ThisPart is ever the same...
EndProcedure
Procedure Test3(val1,val2,val3...)
...Code3A - Never the same code...
...Code3B - ThisPart is ever the same...
EndProcedure

So i thought about a subroutine to store only the CodeB part and call this subroutine with GOSUB inside a procedure, like:
Code: Select all
Procedure Test1(val1,val2,val3...)
...Code1A - Never the same code...
Gosub SubRoutine
EndProcedure
Procedure Test2(val1,val2,val3...)
...Code2A - Never the same code...
Gosub SubRoutine
EndProcedure
Procedure Test3(val1,val2,val3...)
...Code3A - Never the same code...
Gosub SubRoutine
EndProcedure
SubRoutine:
...CodeB
Return

So i thought and stored the subroutine code into a new procedure, which works! But this way is very bad for my code, because when calling the main procedure and this is calling a such called sub-procedure, my program runs about factor 100 slower ;( (here an example of the way, that slow down my program)
Code: Select all
Procedure SubRoutine(val1,val2,val3...)
...CodeB
EndProcedure
;---------------------------------------------------
Procedure Test1(val1,val2,val3...)
...Code1A - Never the same code...
SubRoutine(val1,val2,val3...)
EndProcedure
Procedure Test1(val1,val2,val3...)
...Code1A - Never the same code...
SubRoutine(val1,val2,val3...)
EndProcedure
Code: Select all
good reasons would be:
-------------------------------------------------------------
* no performance loose
* small exe filesize
bad reasons would be:
-------------------------------------------------------------
* if you will change or modify anything of the CodeB part, you have not
to change this only onces! You have to change this all there, where you use the same code... (still silly, even if you only want to change one value and have 50 procedures for example)
* filesize of the exe will be bloody big (instead having the routine only once in the whole program)