memchan(n)

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

πŸ’– 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 set and append to 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 (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