Result of passing a type?

Blitz3D Forums/Blitz3D Programming/Result of passing a type?

9572AD(Posted 2006) [#1]
If I have a

instanceOf.myType= new myType

and a

function doStuff(localInstance.myType)
end fucntion

then, when I

doStuff(instanceOf)

does B3D simply create another pointer to the type data already in memory, or does it duplicate all the data in the type?

I'd assume only the pointer, but want to be sure.


John J.(Posted 2006) [#2]
That's correct - it duplicates the pointer, not the data.


Danny(Posted 2006) [#3]
Yep, that works pretty good for passing types..

On tip though, is that it would be wise/safest to always check in a function that the type passed as a parameter 'is valid' - and not NULL; so:

If localInstance = null then runtimeerror "Empty type passed to DoStuff()!"


D.


Tom(Posted 2006) [#4]
Yup, just test if it's Null:

Function myFunc(t.test)
If t=Null return
;continue...
End Function


John J.(Posted 2006) [#5]
Function myFunc(t.test)
If t=Null return

I usually don't do that, because it will cause many bugs to go unnoticed. Of course, it's good to prevent crashes, but it can make tracking down logic bugs really frustrating.


Danny(Posted 2006) [#6]
I wouldn't recomend simply 'Returning' when the type is null since there's obviously something wrong (else why would you call that function in the first place) so best to give some sort of error....


Sir Gak(Posted 2006) [#7]
I agree with Danny. Good advice. If you are calling the function, and there's no info there to be operated on, then you are better off finding out WHY there's nothing there.

A request for help that I see often on these boards is people having problems with Types. A typical question is like this: "I deleted my enemy, and the game crashes, so why is that?" Yes, executing a Return if it's Null is good, but finding our *why* it's Return-ing from a Bull is better still and good programming technique beside.

I also like Danny's post where he said:
If localInstance = null then runtimeerror "Empty type passed to DoStuff()!"


This is a great way to alert you, not only that something's not right, but also a vital clue as to where to start looking for the bug.