Main Menu

Question

Started by Draco9898, July 31, 2004, 04:56:55 PM

Previous topic - Next topic

Draco9898

I was wondering..If I 'functionize' a large part of my game will this create any bottlenecks or slow-downs???  :o
DualCore Intel Core 2 processor @ 2.3 ghz, Geforce 8600 GT (latest forceware drivers), 2 gigs of ram, WIN XP home edition sp2, FireFox 2.

"You'll no doubt be horrified to discover that PlayBasic is a Programming Language." -Kevin

kevin

That would depend on how often you call this function and how many locals it contains.  

Lets say the function contains 1000 local variables, every time you call this function, those varioables are allocated.  So if you called it a bunch of times in tight loop, then yes there will be some serious overhead.  As there would in any language.  

but calling it few times per update it's a big deal.

If you want the scope protection of a function, but less overhead and static variables by default,  You can choose to use PSUB for you Big function.

Draco9898

There are no local varibles, its just acessing an array...
should I turn it into a psub?

I looked at the help files for the differences between Psubs and Functions, but I didn't get it...
DualCore Intel Core 2 processor @ 2.3 ghz, Geforce 8600 GT (latest forceware drivers), 2 gigs of ram, WIN XP home edition sp2, FireFox 2.

"You'll no doubt be horrified to discover that PlayBasic is a Programming Language." -Kevin

kevin

Any variable used within the Function will be local, these include temp variables that are used within expressions are resolved...

 If the arrays your accessing are global from with the function, it's hardly an issue then.   As the call of the functin would hardly be doing anything

Functions and Psub look and appear work almost the same.  Psubs are generally faster than functions, but the variables inside them are STATIC (they retain their value forever) while the locals in functions allocated each time it's called , making PSUBS better for small subs that calc a result and return it..

Psub Dist(x1,y1,x2,y3)
dx=x1-x2
dy=y2-y1
d#=sqrt(dx*dx+dy*dy)
EndPsub d#

You can't exit a PSUB though and that's the catch...