UPDsocket recv without allocations?

I have an application where i am receiving / synthesizing data from a number of sources. One source is UDP packets. From what I can find, the only way to receive data from a sock = UDPSocket() is with recv(sock)… which returns a freshly allocated array.

I am receiving packets quickly, so this ends up being a lot of allocations. Timeliness is important, so I don’t want to be constantly triggering garbage collection (not sure how to profile the impact of that). Is there no way to get the data from a UDPSocket into a pre-allocated array? The packets are all the same size.

Thanks.

Sounds like a great submission to the stdlib, since our UDP stack is pretty far underdeveloped still

@nhardy Did you get anywhere with this or find a solution? It would of interest to me.

1 Like

Hello @Larbino1. I had this problem a while ago. I produced a hacked version of a function from Sockets.jl which worked ok but it still had problems with being interrupted by the garbage collector so in the end I used C++ via CxxWrap to do the UDP comms for my program. See here.