Labels In Blitz,Blitz3D...

Miscellaneous Forums/General Discussion/Labels In Blitz,Blitz3D...

... do they take up memory... is there any penalties performance wise for using them, a few of them, as markers for sections of code that i'd rather not make functions, but would like to be able to jump directly to in the editor... i'm not planning on using them as goto targets...

the reason i'm avoiding functions is twofold... i think the jump and returns adds a slight performance penalty, plus... resolving the params may also icur a hit...

thx for any advice...

--Mike

... right /wrong

The label itself does not take up any memory or incur any sort of performance hit. The memory address (or offset) is stored as part of the assembler equivalent of Goto or Gosub when compiled.

A Function without parameters is exactly the same as a Gosub when compiled, as the Function definition is basically turned into a label and the End Function is compiled as a Return. I don't know the internal workings of the Blitz compiler, but having used assembler on other machines in the past I would assume that this is what happens. Therefore, there is no real advantage in using Gosubs over Functions.

I have found lables to be more useful than functions in some cases in the past. Can't remember what i used them for but i can post if i do.

Functions are quite a bit slower than using labels/Gosubs. But, as said before, the gains on readability and structure far outweigh the speed loss.

Speed is the only good reason to use Gosubs, but you may lose speed in other ways. You will probably need a larger number of globals with gosubs. This may create a hidden speed hit.

Just some thoughts.

thx guys... no labels or gotos or gosubs... just a series of instructions within if/else/endif or select/case branches within a single function...

the function serves as the sole update function for a class in my OO engine... and i was just planning to use the labels as markers for quickly locating stuff in the editor...
;------------------------------------------------------------------------------------------------------
;
;						    Gato Class Submarine Class Implementation
;
;       the methods are actually contained within conditional clauses, depending on what is needed
;
;------------------------------------------------------------------------------------------------------


Function UpdateGatoClassSubs(this.tObject)


    ;----------------------------------------------------------------------- one time initialization
    ;
	If this\status=0
	    ; 														 sub must be modelled to actual scale  
		gatoDraught=8 ; 				  draught is represented as 1/2 the real world draught
		gatoDepth(this\objID)=gatoDraught
		gatoIndicatedDepth(MaxGatoClassSubs)=gatoDepth(this\objID)-gatoDraught
		PositionEntity this\hEntity,-300,gatoDraught,400,True
			
	   this\status=1
	EndIf
	
	
	
	;--------------------------------------------------------------------------------------- always
	;
	
	
	gatoIndicatedDepth(MaxGatoClassSubs)=gatoDepth(this\objID)-gatoDraught
	
	;----------------------------------------------------- if on the surface 
	;
	If gatoDepth(this\objID)>(gatoDraught-6)
	
		;												   roll with the waves
		;
	    ;PositionEntity  this\hEntity,EntityX(this\hEntity),gatoDepth(this\objID)+(Sin(gatoDeckAngle(this\objID))/-10),EntityZ(this\hEntity)
		MoveEntity this\hEntity,0,Sin(gatoDeckAngle(this\objID))/-16,gatoActualSpeed(this\objID)
    	RotateEntity  this\hEntity,-.4+(Sin(GatoDeckAngle(this\objID))),0,0
    	gatoDeckAngle(this\objID)=gatoDeckAngle(this\objID)+1.2	  
		
		;													check not exceeding surfaced Y limits
		;
	 	If EntityY(this\hEntity)>gatoDraught Then PositionEntity(this\hEntity,EntityX(this\hEntity),gatoDraught,EntityZ(this\hEntity))
	 	;If EntityY(this\hEntity)<(gatoDraught*-1) Then PositionEntity(this\hEntity,EntityX(this\hEntity),(gatoDraught*-1),EntityZ(this\hEntity))
	    MoveEntity this\hEntity,0,0.02,0
	EndIf
	
.throttle	
	;----------------------------------------------------------------- register throttle changes
	;										1=slow 2=1/3 3=2/3 4=std 5=full 6=flank
	Select gatoThrottlePos(this\objID)
	
	  Case 0 
	    gatoTargetSpeed(this\objID)=.0
	  Case 1 
        gatoTargetSpeed(this\objID)=.5

	  Case 2 
	    gatoTargetSpeed(this\objID)=1
	  Case 3 
	    gatoTargetSpeed(this\objID)=1.5
	  Case 4
	    gatoTargetSpeed(this\objID)=2
	  Case 5
		gatoTargetSpeed(this\objID)=2.3
	  Case 6
	    gatoTargetSpeed(this\objID)=2.5
    End Select
   ....
   ....
   ....	


that should be ok, right...

--Mike

I had to add a couple of labels to the Xmas Bonus menu/game/gameover etc loop as the paths the user could take were fairly complex, but it was clear and worked fine.

thx again for the help guys...

--Mike

to add bookmarks in editors I generall create a comment with a particular marker

; ## Todo

; ** Input handler.

; !! Bugged

; @@ relies on external code



etc...

I just do an edit->find for ## to jump to the next thing I need to finish when I open a project in the IDE :)

good idea vp...

--Mike

Yeah when I write long docs, anything that isn't done or needs clarifying I put *** by it. Then I can search the doc and finish those points of at a later date.

What is a 'Label'? I am not sure if this is something new to me or just something I already know but call it something else. I wasn't aware of 'Labels' in Blitz 3D. Can someone just define what you are talking about?

EDIT:
Is one of these (preceded with a fullstop)?:

.blahblah

a lable is like this:

.gohere ;the lable 
;some code
goto gohere ;the goto

you use it when you want to jump to a specific place in your code. Hope that makes sense

Ah, it is what I thought it was - I just don't call them labels. In fact, I haven't got a name for them - just do them.

Labels can be used to Restore specific Data sets, too.

yeah although I never bother with Data anymore, I used it on Tetroid for the shapes though.