fifo(n)

πŸ“¦ version 2.3, in fedora 43, fedora 44

πŸ’– fifo β€” the u-turn channel of your dreams πŸ’–

okay bestie, listen. this is the fifo(n) page from the memchan family, and it's lowkey one of the most useful little gremlins in Tcl. let me put you on.


✨ NAME ✨

fifo β€” Create and manipulate u-turn fifo channels πŸŒ€


🌸 SYNOPSIS 🌸

package require Tcl

package require memchan

fifo

that's it. that's the whole vibe. no cap.


πŸŽ€ DESCRIPTION πŸŽ€

so fifo makes a stream-oriented in-memory channel and hands you back its handle. that's the whole thing. it's giving "i contain multitudes but also i'm just a handle."

there is no restriction on the ultimate size of this channel. none. zero. it will always grow as much as is necessary to accommodate whatever data you write into it. it's a grower, not a shower, and honestly? iconic behavior. πŸ’…

now here's the part where it's different from its cousin β€” in contrast to the channels generated by memchan, a channel created here effectively represents an U-turn πŸ”„. everything you write into it can be read out… but only in the same order. so it's a queue, basically. first in, first out. (the name was right there the whole time, bestie, i'm not even joking.)

this also means that a fifo channel is not seekable. no rewinding, no jumping around, no seek. the past is the past. periodt.

the channels created here can be transferred between interpreters in the same thread and between threads, but only as a whole. you cannot use them to create a bi- or unidirectional connection between two interpreters. not a bridge. not a tunnel. just a whole entire channel, yeeted intact. 🫢


🌈 the read-only options 🌈

memory channels created by fifo provide two read-only options which you can query via the standard fconfigure command. they are:

  • -length β€” this value is the number of bytes currently stored in the queried memory channel. how much stuff is in there right now.
  • -allocated β€” this value is the number of bytes currently allocated by the queried memory channel. and heads up: this number is at least as big as the value of -length. always. it's β‰₯ -length, no exceptions.

πŸ”₯ fileevent tea πŸ”₯

since the channels generated by fifo grow as necessary, they are always writable. which means… a writable fileevent-handler will fire continuously. like. constantly. it never stops. it's that friend who texts "hey" and then nothing else, forever. be aware. 😭

they're also readable if they contain more than zero bytes. under this conditions, a readable fileevent-handler will fire continuously too. so yeah. continuous. you've been warned. πŸ’€

ngl this is the part where you sit with your choices and think about whether you actually want a fileevent handler on this thing. because it will not chill.

πŸ‘‘ NOTES πŸ‘‘

one possible application of memory channels created by memchan or fifo is as a temporary storage device to collect data coming in over a pipe or a socket. classic move, honestly.

and if part of the processing of the incoming data is to read and process header bytes or similar, then fifo is easier to use, because they do not require seeking back and forth to switch between the assimilation of headers at the beginning and writing new data at the end. no bouncing around. just vibes, in order, front to back. πŸ¦‹


πŸ’œ SEE ALSO πŸ’œ

  • fifo2
  • memchan
  • null

go read those too, bestie, they're all in the same friend group.


⭐ KEYWORDS ⭐

channel, fifo, i/o, in-memory channel, memchan, stream


Copyright (c) 1996-2003 Andreas Kupries <andreas_kupries@users.sourceforge.net>


and that's the whole page, bestie! πŸŽ€ this was Memory channels, version 2.1, and the page is fifo(n) β€” so go forth, make your u-turn channels, and remember: only in the same order. mwah. πŸ’–βœ¨

πŸ“¦ where this page comes from