Skip to content
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

why am i forced to make copies? #424

Closed
ziereis opened this issue May 3, 2024 · 2 comments
Closed

why am i forced to make copies? #424

ziereis opened this issue May 3, 2024 · 2 comments

Comments

@ziereis
Copy link

ziereis commented May 3, 2024

Every networking library ive ever used exposes the send function by a pointer or reference to the data that should be sent. Why is this not the case for this library? i can not understand why i need to copy messages and make extra allocations. Same applies for reading data from the socket. Why can i read it into a buffer?

@agalakhov
Copy link
Member

Because this allocation must exist somewhere since sending is not always immediate, sometimes data are kept in the outgoing queue. Most libraries do it internally. We decided to expose it to make it obvious and to put it into the external interface in order not to provide false sense of "zero-copying".

We're actually discussing possibilities of optimizing this part (see #96) but there is no solution without any drawbacks. For example, forcing to use Arc is even worse than forcing to use clone() if the environment is single-threaded. That's why both Rc and Arc exist. Copying of small data within one thread could be less expensive than doing thread-safe atomic increment on a multiprocessor system. We really want to provide a free choice of these possibilities, but the general solution is still in discussion phase, and I personally don't have much time to implement such things right now. Feel free to jump in.

@daniel-abramov
Copy link
Member

As @agalakhov mentioned, there is an issue (#96) that tracks the change that would lift such a limitation in a library, so I think we can close this one (otherwise, it's really hard to keep track of things when they are discussed in separate issues).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants