Closed darsvador closed 3 years ago
Maybe somehow related to #182? (i.e. is it a generalization of that issue?)
uvw
allocate memory function:
https://github.com/skypjack/uvw/blob/77af4a3fc4d932a52652807506fc50d0e58e875c/src/uvw/handle.hpp#L40-L43
uvw
read callback:
https://github.com/skypjack/uvw/blob/77af4a3fc4d932a52652807506fc50d0e58e875c/src/uvw/stream.h#L131-L134
uvw
DataEvent
(UDPDataEvent
):
https://github.com/skypjack/uvw/blob/77af4a3fc4d932a52652807506fc50d0e58e875c/src/uvw/stream.h#L64-L67
https://github.com/skypjack/uvw/blob/77af4a3fc4d932a52652807506fc50d0e58e875c/src/uvw/udp.h#L32-L35
Since the memory allocation function uses operator new
, the implementation of DataEvent
assumes that unique_ptr uses the default deleter. Because these are not customizable, I can't control the process of allocating memory even if I have a chance to avoid operator new
.
How do you envision setting it up? Because doing it on a per-handle basis seems a little annoying.
I think the default behavior is enough for most cases. Sometimes when the user wants to buffer reuse such as using a C library which buffer pointer can be then realloc
etc, they must define an allocator
which provides a deleter and an allocate function.
uvw
default allocator
could be a simple trait of new []
and std::default_delete<char[]>
.
Do you mind creating a PR for that? Not even a completely refined one, but having something that shows how you would intervene would be great if possible.
OK, I will make a basic implementation of my idea.
@skypjack I have created a PR of the custom allocator. Please have a look.
Hi, sorry for being late. I had some personal problems over the weekend and I didn't even turn on my pc. Thank you for the PR. I'm tryng to keep up with all the things I left behind. I'll look into it soon. 👍
I guess we can close this. Feel free to reopen or comment the issue if you want to discuss it further. Thanks.
UVW
provides auv_alloc_cb
to allocate memory withnew
, but this is inconvenient when I want to manage the buffer more complex or usemalloc
to allocate memory.