-
Notifications
You must be signed in to change notification settings - Fork 120
Open
Labels
Description
Currently, chan provides chan_send
to send data by void*
argument. But someone may want to send int/long/double/char etc.
How do you think? And I worry about someone may mistake to use chan and argument pointer. For example.
char buf[256];
while (!chan_is_closed(c)) {
if (condition) {
strcpy(buf, "doA");
} else {
strcpy(buf, "doB");
}
chan_send(c, p);
}
If the chan is possible to do buffering, the buf
will be overwritten. It need to allocation new memory for each sending. My suggestion is adding new function like below.
chan_send_string(c, buf);
chan_recv_string(c);
chan_send_int(c, 3);
chan_recv_int(c);
chan_send_double(c, 4.5);
chan_recv_double(c);
This functions allocate new memory for the types. chan_recv_int
, chan_recv_double
is possible to free the memory automatically. chan_recv_string
will be required to free memory by developers.