From 7aa85dfa64a4e9a3b7965046e6561d99958cb897 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Tue, 2 Apr 2024 10:45:42 +0200 Subject: [PATCH] Reuse buffers to send network data --- common/wivrn_serialization.h | 7 +++++++ common/wivrn_sockets.h | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/common/wivrn_serialization.h b/common/wivrn_serialization.h index ca9277b9..4975834d 100644 --- a/common/wivrn_serialization.h +++ b/common/wivrn_serialization.h @@ -107,6 +107,13 @@ class serialization_packet public: serialization_packet() = default; + void clear() + { + buffer.clear(); + spans.clear(); + spans.push_back({size_t(0)}); + } + void write(const void * data, size_t size) { size_t index = buffer.size(); diff --git a/common/wivrn_sockets.h b/common/wivrn_sockets.h index 87c40009..8090f589 100644 --- a/common/wivrn_sockets.h +++ b/common/wivrn_sockets.h @@ -196,7 +196,8 @@ public: template void send(T && data) { - serialization_packet p; + thread_local serialization_packet p; + p.clear(); uint8_t index = details::Index, std::tuple>::value; p.serialize(index); p.serialize(std::forward(data));