From e06d0d094367eb5563083ba8231683b23aea4883 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Mon, 19 Jan 2026 19:37:25 +0100 Subject: [PATCH] Optimize away a memory allocation --- common/wivrn_sockets.cpp | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/common/wivrn_sockets.cpp b/common/wivrn_sockets.cpp index b4c881af..875040ae 100644 --- a/common/wivrn_sockets.cpp +++ b/common/wivrn_sockets.cpp @@ -313,24 +313,21 @@ wivrn::deserialization_packet wivrn::UDP::receive_raw() #else buffer.reset(new uint8_t[message_size * num_messages]); #endif - std::vector iovecs; - std::vector mmsgs; - iovecs.reserve(num_messages); - mmsgs.reserve(num_messages); + std::array iovecs; + std::array mmsgs; for (size_t i = 0; i < num_messages; ++i) { - iovecs.push_back({ + iovecs[i] = { .iov_base = buffer.get() + message_size * i, .iov_len = message_size, - }); + }; - mmsgs.push_back( - { - .msg_hdr = { - .msg_iov = &iovecs.back(), - .msg_iovlen = 1, - }, - }); + mmsgs[i] = { + .msg_hdr = { + .msg_iov = &iovecs[i], + .msg_iovlen = 1, + }, + }; } int received = recvmmsg(fd, mmsgs.data(), num_messages, MSG_DONTWAIT, nullptr);