2008-02-24
1. I keep a large collection of text data as a list in memory {text...}
2. I want to search this data.
Here's what happens.
set match [lsearch -regexp $x {needle}]
-> memory usage of the tcl process more than doubles (before: 80MB, after: 200MB)
foreach k $x { if {[regexp -nocase {needle} $k]} {puts "match"}
- >ditto
foreach k $x { if {[regexp -nocase {needle} [list $k]]} {puts "match"}
-> Heureka! total memory usage stays at 80MB.
Note that:
for {set i 0} {$i<120000} {incr i} { set j [lindex $x $i]; string reverse $j; lset x $i $j}
-> memory usage stays at 80MB
I'm still not quite sure what's going on, it's about keeping lists 'pure' I guess. I'm now consulting these pages:
-hans