Symbols - Petewg/harbour-core GitHub Wiki
🔙 Home
Harbour maintains a dynamic symbol table which can store up to 65.535 4.294.967.295 symbols.
Each non-static function, object message, alias, field, private and public name
allocates one item in symbol table. The same names share one symbol.
Below, are the available functions that help exporting several info, regarding the dynamic symbol table.
-
__dynsCount()➜ nSymbols
How much symbols have been already allocated/stored in dynamic symbol table? -
__dynsGetIndex(
<cSymbol>
) ➜ ndsIndex
returns the ordinal index number of the given<cSymbol>
into symbol table. -
__dynsGetName(
ndsIndex
) ➜ cName
returns the name of symbol found inndsIndex
position of symbol table. -
__dynsIsFun(
<cSymbol> | <ndsIndex>
) ➜ TRUE|FALSE
returns.T.
if the given<cSymbol>
(or the symbol in<ndsIndex>
position) has a function/procedure pointer. In other words the returned value will be either:TRUE
if<cSymbol>
is a function/procedure orFALSE
if it's a variable, alias etc. -
__dynsGetPRF(
<ndsIndex>
) ➜ aInfo
profiling function: It returns an array with two items{ nCalls, nTime }
where:
nCalls
item represents the number of times the function or procedure, found in<ndsIndex>
position of symbol table, has been called
nTime
item represents the total time that has been consumed in executing that function/procedure.-
NOTES:
-
__SetProfiler( .T. )
must have been invoked prior to calling this function, otherwise values of both items will be zero! - In order to use the Harbour Profiler, Harbour itself must have been built using HB_USE_PROFILER, since profiler code (in HVM) is disabled, by default.
-
-
NOTES:
-
__dynsN2Ptr(
<cSymbol>
) ➜ pSymbol
name to pointer conversion. (valtype:P
) -
__dynsN2Sym( cSymbol ) ➜ sSymbol
name to symbol conversion. (valtype:S
) -
__dynsP2Name( pSymbol ) ➜ cName
pointer to name conversion. (valtype:C
) -
__dynsVerify() ➜ nResult
internal function used to debug dynamic symbol integrity. Returns0
=Ok,< 0
=Problem? -
__SetProfiler( .T.|.F. )
turns the profiler mechanism ON or OFF. Used along with__dynsGetPRF()
to allow gathering symbol usage data.
In a message in Harbour users group, Przemek wrote the bellow comment and code regarding the size of dynamic symbol table:
In normal applications 65535 is reasonable limit,
any how if someone wants to exploit it then it can always
do that regardless of the limit, i.e. using code like:
PROCEDURE main()
LOCAL i := 0, v
WHILE .T.
v := "var" + LTrim( str( ++i ) )
PRIVATE &v
ENDDO
RETURN
🔙 Home