# UPDsocket recv without allocations?

**URL:** https://discourse.julialang.org/t/updsocket-recv-without-allocations/93481
**Category:** Performance
**Tags:** sockets
**Created:** [January 25, 2023, 1:58am UTC](https://discourse.julialang.org/t/updsocket-recv-without-allocations/93481 "2023-01-25T01:58:19Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![nhardy](https://avatars.discourse-cdn.com/v4/letter/n/9fc348/32.png) [@nhardy](https://discourse.julialang.org/u/nhardy)
#### Post date: [January 25, 2023, 1:58am UTC](https://discourse.julialang.org/t/updsocket-recv-without-allocations/93481/1 "2023-01-25T01:58:19Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![jameson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jameson/32/23_2.png) [@jameson](https://discourse.julialang.org/u/jameson)
#### Post date: [January 25, 2023, 4:17am UTC](https://discourse.julialang.org/t/updsocket-recv-without-allocations/93481/2 "2023-01-25T04:17:12Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Larbino1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/larbino1/32/37831_2.png) [@Larbino1](https://discourse.julialang.org/u/Larbino1)
#### Post date: [April 30, 2024, 4:33pm UTC](https://discourse.julialang.org/t/updsocket-recv-without-allocations/93481/3 "2024-04-30T16:33:57Z")

</div>

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

---

<div class="post-metadata">

### Author: ![tt1234567](https://avatars.discourse-cdn.com/v4/letter/t/dec6dc/32.png) [@tt1234567](https://discourse.julialang.org/u/tt1234567)
#### Post date: [May 1, 2024, 8:32am UTC](https://discourse.julialang.org/t/updsocket-recv-without-allocations/93481/4 "2024-05-01T08:32:20Z")

</div>

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](https://discourse.julialang.org/t/how-to-pass-a-buffer-to-a-c-callback-function/87716).
