In an effort to expand on this concept a bit, here is an example ScriptBasic extension module using BCX Universal (Ubuntu 32) to create the Linux shared object. (libtrial.so) This allows you to use ScriptBasic to get the meat of your project defined and use BCX to create dynamic called C functions to increase performance in sections of your code. In the end, your are able to compile your project to a small footprint executable (wrapped PCODE in C) and link dynamically to SB's runtime and extensions.
trial.bas$DLL
$EXECON "-I/usr/src/scriptbasic"
#include <basext.h>
'besVERSION_NEGOTIATE
FUNCTION versmodu(Version as integer, pszVariation as string, ppModuleInternal as void ptr ptr) as integer export
FUNCTION = INTERFACE_VERSION
END FUNCTION
'besSUB_START
FUNCTION bootmodu(pSt as pSupportTable, ppModuleInternal as void ptr ptr, pParameters as pFixSizeMemoryObject, pReturnValue as pFixSizeMemoryObject ptr) as integer export
DIM pEo AS pExecuteObject
DIM pL AS long ptr
besMODULEPOINTER = besALLOC(sizeof(long))
IF besMODULEPOINTER = NULL THEN FUNCTION = 0
pL = (long *)besMODULEPOINTER
*pL = 0
FUNCTION = 0
END FUNCTION
'besSUB_FINISH
FUNCTION finimodu(pSt as pSupportTable, ppModuleInternal as void ptr ptr, pParameters as pFixSizeMemoryObject, pReturnValue as pFixSizeMemoryObject ptr) as integer export
DIM pEo AS pExecuteObject
FUNCTION = 0
END FUNCTION
'besFUNCTION
FUNCTION trial(pSt as pSupportTable, ppModuleInternal as void ptr ptr, pParameters as pFixSizeMemoryObject, pReturnValue as pFixSizeMemoryObject ptr) as integer export
DIM pEo AS pExecuteObject
DIM pL AS long ptr
PRINT "Function trial was started..."
pL = (long *)besMODULEPOINTER
(*pL)++
besRETURNVALUE = besNEWMORTALLONG
LONGVALUE(besRETURNVALUE) = *pL
PRINT "Module directory is ";(char*)besCONFIG("module")
PRINT "dll extension is ";(char*)besCONFIG("dll")
PRINT "include directory is ";(char*)besCONFIG("include")
FUNCTION = 0
END FUNCTION
ttbcx.sbDECLARE SUB trial ALIAS "trial" LIB "libtrial"
modptr = trial()
PRINT "Module Pointer = ",modptr,"\n"
Resultsroot@Laptop:/home/jrs/bcx# scriba ttbcx.sb
Function trial was started...
Module directory is /usr/local/lib/scriba/
dll extension is .so
include directory is /usr/share/scriba/include/
Module Pointer = 1
root@Laptop:/home/jrs/bcx#
A good example of how a C function can speed things up dramatically is the use of the
SPLITA() function. You will see what I mean if you try to take a delimited string and build an array from it with a loop structure compared to using SPLITA() to do it.