FASTPROC/END FASTPROC statements  

Purpose

Define a FastProc code section.

Syntax

FASTPROC ProcName [([arguments])] [THREADSAFE] [AS LONG]

  [statements...]

END FASTPROC [= ReturnValue]

Remarks

A Fast Procedure (FASTPROC) is a highly simplified form of SUB or FUNCTION which executes much faster than its fully-featured counterparts.  It allows a maximum of two BYVAL LONG arguments, and may optionally return a LONG result.  The arguments are always processed as register variables for maximum execution speed.  No stack frame is ever created, so there are other limitations detailed below.  The programmer may then decide when it is appropriate to accept these trade-offs in exchange for maximum efficiency.

All executable code must reside in a Sub, Function, Method, FastProc, or Property block.  You cannot define a procedure inside another procedure.  A FASTPROC is a subroutine-like block of statements which is invoked with the CALL statement.  A FASTPROC may also be invoked without the word CALL, which is then implied.  If the CALL word is omitted, the parentheses around the argument list must also be omitted.

ProcName must be unique: no variable, Function, Sub, Method, FastProc, Property or label can share the same name.

THREADSAFE

If you include the option THREADSAFE, PowerBASIC automatically establishes a semaphore which allows only one thread to execute it at a time.  Others must wait until the first thread exits the THREADSAFE procedure before they are allowed to begin.

Restrictions

Most of the restrictions of a FASTPROC stem from the fact that no stack frame is created.

  • A maximum of two parameters are allowed, and they must be defined as BYVAL LONG integers.  An optional return value, if used, must be defined as LONG integer.

  • LOCAL variables are not available because there is no stack frame.  This includes Register variables, which are by definition, Local variables.  Instead, one or two parameters are automatically given status as Register Variables.  By default, all new variables are assigned STATIC scope.

  • ON ERROR GOTO, RESUME, and TRY blocks are not available.  You should explicitly test for errors with IF ERR THEN...

  • DATA and READ$ are not available.

  • FUNCNAME$ is not available.

  • COMMON, IMPORT, and EXPORT options are not available.

See also

DECLARE, EXIT, FUNCNAME$, GLOBAL, INSTANCE, ISMISSING, LOCAL, METHOD, PROPERTY, STATIC, SUB, THREAD CREATE, THREADID, THREASAFE