* Alexandru <
[email protected]>
| I have some C functions that perform fast operations on lists of numbers.
| Until now, I transfer Tcl data in the shape of lists to those C functions.
| In some cases the Tcl data is stored in dictionaries so I run some Tcl
| loops over the Tcl dict, put the needed data into lists and finally
| pass the lists to the C function.
| Since performance is paramount, I'm thinking that the above method might not be the fastest.
| If I would directly pass the Tcl dict to the C function, would that be faster?
Not copying data sounds always faster to me...
https://www.tcl.tk/man/tcl8.6/TclLib/DictObj.html
lists the C interface to dicts. Basically you get the TclObjs for the
keys and/or values in the dict. You would then call Tcl_GetIntFromObj()
on the value ptr.
| What if the Tcl dict is "nested" so there are multiple keys that lead to a value?
You would need some information on the nesting depth, since the value
has no "I'm a dict" label attached. You could check whether Tcl_GetIntFromObj(valueptr) is successful and if not, try to use it as multiple-level dict.
| Can I (efficiently) access nested dicts with the C API?
I would say 'yes', since in nested dicts the values are themselves just
dicts instead of plain... well... 'values'. Haven't tried that myself, though.
HTH
R'
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)