On 31/05/2012 03:22, Jay wrote:
> In my case data file is huge.. I mean really huge.. could be more than
> 20gb .gz compressed text data. Data is structured and considered safe
> and free of unbalanced "enclosing" characters. My initial attempt to
> while {[gets $fd line]>=0} {} could not process full file because of
> some stack overflow in 32bit tclsh.
Hmm, well you certainly cannot just [source] a script that large. One of
the lesser-known restrictions of Tcl is that no data object[*] can get
larger than 2GB at present, even on a 64-bit system (it's also true on a
32-bit system, but feels like less of a restriction there). This is due
to what is perhaps the oldest standing open Tcl bug (assigned to me too)
and it's all tangled up in the use of types across a lot of Tcl's C API
so fixing it is very disruptive. :-(
The [source] command is actually pretty dumb though; it just reads the
whole file into memory and then does (in effect) an [eval] on it.
Reading a bit at a time and evaluating that will work better.
Donal.
[* Technically, our memory allocator can't allocate anything longer than
2GB and many string functions are limited there too. ]