Hi everyone, I'm working on a simple network application and I'm new to the 
libuv, so I have this noob question to ask

If I have an application which use only one loop, with many tcp/udp handler 
registered on it, is it safe to use static buffer in uv_alloc_cb like this?

static char buffer[65535] = {0};

void alloc_buffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t 
*buf) {
  buf->base = (char*)buffer;
  buf->len = 65535;
}

In my imagine, the event loop of libuv would work in a SINGLE thread with 
the following way:
1. System polled an event
2. Invoke uv_alloc_cb
3. Invoke uv_recv_cb with the allocated buffer and other infomation
4. After #3 ends, back to #1

In this circuit, it's easy to point out that the allocated memory will be 
only used in uv_recv_cb and will not been overwritten before #3 ends, so in 
this situation I think use a static buffer here is possible, but I don't 
know whether the process I imagine is correct.

If my imagine is correct, is it safe to use the static buffer?

More questions if it's safe:
1. Does libuv has same behaviour on different platform?
2. Will thread-based handler (file or something else) change the behaviour?

Thanks!!! 

-- 
You received this message because you are subscribed to the Google Groups 
"libuv" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to libuv+unsubscr...@googlegroups.com.
To post to this group, send email to libuv@googlegroups.com.
Visit this group at https://groups.google.com/group/libuv.
For more options, visit https://groups.google.com/d/optout.

Reply via email to