Subject: Help! Extensions which hold state ... - DN [1]


Dave Ashley <dtashley@my-deja.com> - 29 May 2000 - comp.lang.tcl

 I'm writing a Tcl extension (in 'C') which will generate random
 numbers.  However, the extension may have multiple seeds, each named
 and maintained independently.  So, in a Tcl script, the command to get
 a random number may look like:

 set num [pwr_res_random -seeded seed_name]

 Each seed_name would be independent ... i.e. as if it were a separate
 random number generator.

 Here are my question(s):

 To achieve this behavior, each time the extension is called, I would
 examine the seed_name, compare it against a table of seed_name's that
 have been used before, and look for a match.  I would assume that
 string space and so forth for tables can just be allocated with
 Tclp_Alloc(), to build whatever data structure seems convenient.  I
 would also assume that since there would presumably be a small number
 of seed_name's, etc., that a linear search might be OK and hashing
 isn't necessary.

 a)I allocate using Tclp_Alloc() and I deallocate using Tclp_Free() from
 the function registered as the cleanup function when the extension is
 registered, right?

 b)Does Unicode enter into any of this, in how I compare and match
 strings in Tcl_Objs?

 c)Any other advice or suggestions?

 Thanks, Dave.

 ------------------------------------
 Dave Ashley, DTASHLEY@AOL.COM

 Sent via Deja.com http://www.deja.com/
 Before you buy.

Last modified
2000-07-20

(195.108.246.52)

Note: you are looking at
the snapshot of an old wiki
- much of this information
is likely to be very outdated