Giter Club home page Giter Club logo

Comments (5)

skypjack avatar skypjack commented on June 9, 2024

Why not setting the allocation functions using the same utilities of libuv? Is there any problem with it?

from uvw.

hihig2001 avatar hihig2001 commented on June 9, 2024

oh am I misunderstood something?

below codes are something I tracked.

template<typename T, typename U>
class StreamHandle: public Handle<T, U> {
    void read() {
        this->invoke(&uv_read_start, this->template get<uv_stream_t>(), &this->allocCallback, &readCallback);
    }
}
template<typename T, typename U>
class Handle: public Resource<T, U> {
    static void allocCallback(uv_handle_t *, std::size_t suggested, uv_buf_t *buf) {
        auto size = static_cast<unsigned int>(suggested);
        *buf = uv_buf_init(new char[size], size);
    }
}

I thought that problem rise this line of code

*buf = uv_buf_init(new char[size], size);

I'd like to pass pre-allocated buffer that I'm gonna re-use over and over.
In that way I understand that there should be a way that I can pass my pre-allocated buffer to uv_buf.base.

Is there are something that I misunderstood or miss some of functionality in libuv or uvw?

from uvw.

skypjack avatar skypjack commented on June 9, 2024

Hi, sorry for the late reply, I'm on vacation and also trying to have a real break from my dev life. 😅
I see what you mean. Consider that we're about to merge branch v3 that is a HUGE change to the library, both in terms of performance and compilation time.
Can we consider this as a feature request to add allocator support to that version? It seems to me the only viable solution. Any other idea?

from uvw.

0EVSG avatar 0EVSG commented on June 9, 2024

+1 for the ability to inject a custom buffer allocation callback.

First of all new is a lot of overhead compared to reusing buffers from an allocation pool. Also it looks like your current implementation effectively prevents recvmmsg() for UDP, which is the use case I'm evaluating now. The suggested buffer size is given as max UDP datagram size, but libuv requires a multiple of that for recvmmsg(). Rather crude implementation from libuv side too, but that's what it is now.

from uvw.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.