Tcl是否进行了脚本编写者控制的内部输入缓冲?以下代码是否可能浪费熵(读取超过1个字节),如果是,我该如何防止它?
set stream [open "/dev/srandom"]
chan configure $stream -translation binary
set randomByte [chan read $stream 1]
答案 0 :(得分:4)
是的,tcl默认为缓冲并且会浪费任务(只有一个read
电话会决定移交)。
我认为你可以用
来阻止它chan configure $stream -buffering none
但不,-buffering
对输入队列没有影响(内部不是单个缓冲区)。
然而,
chan configure $stream -buffersize 0
正如我在stdin
下strace
的实验中看到的那样,可以解决问题。它使任何输入进入大小为1的read
s(系统调用)(TCL read
的参数无关紧要),因此对于正常使用它会非常慢