-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
primitive values #7
Comments
👍 Yes, this would be a good addition to the API. I think int chan_send_int(chan_t* chan, int data)
{
int* wrapped = malloc(sizeof(int));
*wrapped = data;
int success = chan_send(chan, wrapped);
if (success != 0)
{
free(wrapped);
}
return success;
} What I'm not sure about is how Thoughts? |
Right. Or how about this? This is way to hide freeing code. int n;
char buf[256];
chan_recv_int(c, &n);
chan_recv_string(c, buf, sizeof(buf)); |
I think this looks good.
|
Based on discussion in this PR, I think we will look at making channels "typed." |
So, thinking more about typed channels, I'm wondering how useful it would actually be to store the type on |
Agreed. We will have to add new types for each users want. |
Currently, chan provides
chan_send
to send data byvoid*
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.
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.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.The text was updated successfully, but these errors were encountered: