memchan(n)
π memchan β the manual, but make it cute π
okay bestie, buckle up, we're talking about memchan (section n of the manual, if you're keeping score) β Create and manipulate memory channels. yes it's giving "what even is a memory channel" and yes I will explain. π«Ά
β¨ SYNOPSIS β¨
package require Tcl
package require memchan
memchan ?-initial-size len?
πΈ DESCRIPTION πΈ
so this one page is doing double duty, no cap β it documents both the whole package and the command memchan itself. main character energy fr.
The package hands you a bunch of in-memory channels, and you can use them to:
- capture stream-like information in a natural way instead of using
setandappendto manipulate strings (like... why would you do that to yourself bestie π) - or to transfer data between interpreters, whether they're in the same thread or not.
π COMMAND π
memchan ?-initial-size len?
This creates a chunk-oriented in-memory channel and returns its handle. slay. π
If you specify an initial size, the system will pre-allocate len bytes of buffer space for the contents. And no, that is not a restriction on the ultimate size of the channel β it will always grow as much as is necessary to accommodate the data written into it. it's flexible like that. β¨
β οΈ real talk though: the channels created here can be transferred between interpreters in the same thread and between threads, but only as a whole. It is not possible to use them to create a bi- or unidirectional connection between two interpreters. periodt.
π the read-only options π
Memory channels created by memchan provide two read-only options which you can query via the standard fconfigure command. They are:
-lengthβ the value of this option is the number of bytes currently stored in the queried memory channel.-allocatedβ the value of this option is the number of bytes currently allocated by the queried memory channel. This number is at least as big as the value of-length.
π¦ fileevent tea π¦
Since the channels generated by memchan grow as necessary, they are always writable. Which means... a writable fileevent-handler will fire continuously. yeah. constantly. it's a lot. π
The channels are also readable if they contain more than zero bytes and the seek location is not at the end of the channel. Under these conditions a readable fileevent-handler will fire continuously too. π
π heads up bestie: writing to such a channel usually occurs at the end, thus suppressing readable events. This also means that users have to take care to seek the channel to a location before the end before trying to read data back. don't skip that step, I'm begging.
π SEE ALSO π
fifo, fifo2, null, random, zero
β KEYWORDS β
channel, chunk, i/o, in-memory channel, memchan
π COPYRIGHT π
Copyright (c) 1996-2003 Andreas Kupries <andreas_kupries@users.sourceforge.net>
okay that's the whole thing, you ate that. π
β¨ This was Memory channels, version 2.2, and it lives at memchan(n) β thanks for reading my TED talk, ily, go write some channels π«Άππ¦
π¦ where this page comes from
- fedora 43: memchan 2.3-34.fc43 Β· LicenseRef-Callaway-MIT AND LicenseRef-Callaway-Public-Domain
- fedora 43: memchan 2.3-34.fc43 Β· LicenseRef-Callaway-MIT AND LicenseRef-Callaway-Public-Domain
- fedora 44: memchan 2.3-35.fc44 Β· LicenseRef-Callaway-MIT AND LicenseRef-Callaway-Public-Domain
- fedora 44: memchan 2.3-35.fc44 Β· LicenseRef-Callaway-MIT AND LicenseRef-Callaway-Public-Domain
- Copyright (c) 1996-2003 Andreas Kupries <andreas_kupries@users\&.sourceforge\&.net>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms