On Sun, Dec 8, 2013 at 8:20 PM, Saúl Ibarra Corretgé <[email protected]> wrote: > On 12/8/13 8:03 PM, Thiago Arruda wrote: >> >> Hi >> >> I'm writing a small program that reads messages from a stream. Before >> each message, an integer will arrive specifying the size of the >> following message. >> >> I understand libuv will call my own function to allocate buffers with a >> suggested size, but since I know the size of the incoming message, I >> think it makes more sense to use that as the buffer size(Please correct >> if my assumption is wrong, I'm not an expert C programmer). >> >> What would be the 'pretty' way to handle this in libuv? I would rather >> not use global variables to store the size of the next message. >> > > Depends on what you'll do with that data, I guess. If you need to copy it, > then you may as well create a 64k statically allocated buffer and reuse it > every time. > > If you want to use that number from the previous message for preallocating > the next buffer size, then you can create a structure of your own to store > that data and put it in the handle->data field. > > > Cheers, > > -- > Saúl Ibarra Corretgé > http://bettercallsaghul.com > > > -- > 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 http://groups.google.com/group/libuv. > For more options, visit https://groups.google.com/groups/opt_out.
Saúl, thanks for the response. Even if I preallocate the buffer, it still isnt clear how to do it in libuv. Here's how I would do it in plain C: http://pastebin.com/TAuxUqP7 As you can see, its a loop where each iteration reads the size then the data. What would be the best way to achieve the same behavior in libuv? -- 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 http://groups.google.com/group/libuv. For more options, visit https://groups.google.com/groups/opt_out.
