Version 3 of Some observations on behind-the-scenes actions of Tcl

Updated 2008-02-24 01:56:05 by hans

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:

list shimmering pure list.

-hans