Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tcl variable size limit

I am writing a Tcl script which will be used on an embedded device. The value of a variable in this script will be coming from a text file on the system. My concern is that if the source file is too big this may crash the device as there may not be enough memory to store the entire file. I wonder if the size of the variable can be limited so when feeding the variable it does not exhaust the entire amount of memory.

Also, if possible to limit the size of the variable will it still be filled with as much information as possible from the source file, even if the entire file cannot be fed into the variable?

like image 656
torta Avatar asked Dec 27 '22 19:12

torta


1 Answers

You can limit the size of the variable by specifying the number of characters to read from the file. For example:

set f [open file.dat r]
set var [read $f 1024]

This code will read up to 1024 characters from the file (you'll get less than 1024 characters if the file is shorter than that, naturally).

like image 139
Eric Melski Avatar answered Feb 08 '23 22:02

Eric Melski