Creating a TCL-accessible array in a C module is trival. Just pass
the name of the TCL array variable to the C module, then in the C
code, do:
if (Tcl_SetVar2(interp, arrayname, subscript, val, TCL_LEAVE_ERR_MSG) == NULL) {
return TCL_ERROR;
}
Args 2-4 are just simple strings. The array name you pass to C can be
an ns_share, a local, a global, etc. We had a small TCL routine that
scanned a large text file and set an ns_share array. It was taking
several minutes to run. With C, it ran 10x faster.
You use Tcl_GetVar to read simple TCL vars in C, or Tcl_GetVar2 to
read TCL array vars in C. Again, these can be local, global, or
ns_shares. Yet another reason why nsv's aren't the greatest thing
since sliced bread. ;)
Jim
> If you create a huge ns_set (say, in some custom C code), it can be
> MUCH faster to immediately convert it to a Tcl array or AOLserver nsv
> before further processing in your Tcl code, rather than using the
> ns_set directly - if you do lots of key lookups, it definitely will
> be. I know, I tested it. (And in fact, I left it that way, as I
> never did sit down and figure out how to create and populate a Tcl
> array in C and then hand it to Tcl.)