Sorry for post the duplicate
topic, https://groups.google.com/forum/#!topic/libuv/aergXecdysM is the
same issue.
On Wednesday, September 21, 2016 at 2:12:56 PM UTC+8, Sunny wrote:
>
> Hi, everyone, I'm working on a simple network application and I'm new to
> libuv, so I have a question about the buffer allocation.
>
> If I have only one event loop in application, and I registered many tcp
> and udp handlers on the event loop, does it safe for use the following code
> as uv_alloc_cb?
>
> 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 libuv will work like this in a single thread:
> system polled --> call allocator --> call uv_recv_cb --> anthoer system
> polled --> ...,
> so the memory allocated in uv_alloc_cb will only been used in the
> uv_recv_cb and will not been overwrite before uv_recv_cb end, it seems safe
> to use static memory in the loop in such situation, but I don't know
> whether libuv do it actually like this.
>
> And more question if libuv actually work like this:
> Will it have different behaviour in different platform?
> Will the behaviour changes in some special situation(like thread-based
> handler been added to loop)?
>
> 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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/libuv.
For more options, visit https://groups.google.com/d/optout.