From 61b667a4aa3a1e937cc91eab142536ce6f052632 Mon Sep 17 00:00:00 2001 From: Green Sky Date: Sat, 16 Mar 2024 11:30:55 +0100 Subject: [PATCH] reserve memory to reduce number of allocations in hotspots especially on the sender side --- solanaceae/ngc_ft1/ngcft1.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/solanaceae/ngc_ft1/ngcft1.cpp b/solanaceae/ngc_ft1/ngcft1.cpp index a487c42..2710178 100644 --- a/solanaceae/ngc_ft1/ngcft1.cpp +++ b/solanaceae/ngc_ft1/ngcft1.cpp @@ -98,6 +98,7 @@ bool NGCFT1::sendPKG_FT1_DATA( // check header_size+data_size <= max pkg size std::vector pkg; + pkg.reserve(2048); // saves a ton of allocations pkg.push_back(static_cast(NGCEXT_Event::FT1_DATA)); pkg.push_back(transfer_id); pkg.push_back(sequence_id & 0xff); @@ -118,6 +119,7 @@ bool NGCFT1::sendPKG_FT1_DATA_ACK( const uint16_t* seq_ids, size_t seq_ids_size ) { std::vector pkg; + pkg.reserve(1+1+2*32); // 32acks in a single pkg should be unlikely pkg.push_back(static_cast(NGCEXT_Event::FT1_DATA_ACK)); pkg.push_back(transfer_id); @@ -578,7 +580,7 @@ bool NGCFT1::onEvent(const Events::NGCEXT_ft1_init_ack& e) { bool NGCFT1::onEvent(const Events::NGCEXT_ft1_data& e) { #if !NDEBUG - std::cout << "NGCFT1: FT1_DATA\n"; + //std::cout << "NGCFT1: FT1_DATA\n"; #endif if (e.data.empty()) {