What is the maximum buffer size for a channel? sizeof(int)?
And would it be possible (and sensible) to have channels with
non-blocking write, i.e. infinite buffer?
Thanks,
--
// aht
http://blog.onideas.ws
I have a few questions:
What is the maximum buffer size for a channel? sizeof(int)?
And would it be possible (and sensible) to have channels with
non-blocking write, i.e. infinite buffer?
I am not too familiar with channel implementation, but it looks like
instead of pre-allocating a circular buffer ring, perhaps you could
use a normal linked list and allocate memory when values are sent to
the channel?
> It's not possible in the language now. It might be convenient
> in some cases, but I think equally often it would lead to
> programs that used all of memory for buffering.
> Russ
You are probably right generally. But for this toy program of mine
<http://github.com/aht/gosieve/blob/master/sieve2.go#L145> having
non-blocking write is not just a convenience: the program will
deadlock when the buffer is full as there is a feedback loop in the
system that is consumed rather slowly. That program still runs since
it only works with primes in the int range so I can set a big enough
buffer. But theoretically, there are programs whose lives depend on
infinite buffer channels :)
> But theoretically, there are programs whose lives depend on
> infinite buffer channels :)
Theoretically, perhaps, but clearly impossible on real computers. I
can see that in some cases a feedback loop might require a program to
use a top-level select loop, and that that could require the program
to have an awkward structure. But that structure would provide a real
benefit: the program would avoid slowly consuming all available
resources before deadlocking.
Ian
https://github.com/eapache/channels
https://godoc.org/github.com/eapache/channels
It includes channels with "infinite" buffers channels with finite-but-resizable buffers and a bunch of other useful types and functions.