From a4080b4c7bf475cafe5a2cfaf8daa182792ca1a8 Mon Sep 17 00:00:00 2001 From: Lukasz Dorau Date: Wed, 23 Oct 2024 14:00:17 +0200 Subject: [PATCH] Use std::vector instead of std::unique_ptr Use std::vector instead of std::unique_ptr because we do not need to use memset(0) in this case. Signed-off-by: Lukasz Dorau --- test/disjointCoarseMallocPool.cpp | 7 +++---- test/provider_coarse.cpp | 35 +++++++++++++------------------ 2 files changed, 18 insertions(+), 24 deletions(-) diff --git a/test/disjointCoarseMallocPool.cpp b/test/disjointCoarseMallocPool.cpp index d650815dfd..0ff38bb1c0 100644 --- a/test/disjointCoarseMallocPool.cpp +++ b/test/disjointCoarseMallocPool.cpp @@ -395,11 +395,10 @@ TEST_P(CoarseWithMemoryStrategyTest, disjointCoarseMMapPool_random) { const size_t init_buffer_size = 200 * MB; - // Preallocate some memory - std::unique_ptr buffer(new char[init_buffer_size]); - void *buf = buffer.get(); + // preallocate some memory and initialize the vector with zeros + std::vector buffer(init_buffer_size, 0); + void *buf = (void *)buffer.data(); ASSERT_NE(buf, nullptr); - memset(buf, 0, init_buffer_size); const unsigned char alloc_check_val = 11; diff --git a/test/provider_coarse.cpp b/test/provider_coarse.cpp index 7d5c06c090..6995f6abad 100644 --- a/test/provider_coarse.cpp +++ b/test/provider_coarse.cpp @@ -85,11 +85,10 @@ TEST_F(test, coarseProvider_name_no_upstream) { const size_t init_buffer_size = 20 * MB; - // Preallocate some memory - std::unique_ptr buffer(new char[init_buffer_size]); - void *buf = buffer.get(); + // preallocate some memory and initialize the vector with zeros + std::vector buffer(init_buffer_size, 0); + void *buf = (void *)buffer.data(); ASSERT_NE(buf, nullptr); - memset(buf, 0, init_buffer_size); coarse_memory_provider_params_t coarse_memory_provider_params; // make sure there are no undefined members - prevent a UB @@ -159,11 +158,10 @@ TEST_P(CoarseWithMemoryStrategyTest, coarseProvider_wrong_params_1) { const size_t init_buffer_size = 20 * MB; - // Preallocate some memory - std::unique_ptr buffer(new char[init_buffer_size]); - void *buf = buffer.get(); + // preallocate some memory and initialize the vector with zeros + std::vector buffer(init_buffer_size, 0); + void *buf = (void *)buffer.data(); ASSERT_NE(buf, nullptr); - memset(buf, 0, init_buffer_size); coarse_memory_provider_params_t coarse_memory_provider_params; // make sure there are no undefined members - prevent a UB @@ -223,11 +221,10 @@ TEST_P(CoarseWithMemoryStrategyTest, coarseProvider_wrong_params_3) { const size_t init_buffer_size = 20 * MB; - // Preallocate some memory - std::unique_ptr buffer(new char[init_buffer_size]); - void *buf = buffer.get(); + // preallocate some memory and initialize the vector with zeros + std::vector buffer(init_buffer_size, 0); + void *buf = (void *)buffer.data(); ASSERT_NE(buf, nullptr); - memset(buf, 0, init_buffer_size); coarse_memory_provider_params_t coarse_memory_provider_params; // make sure there are no undefined members - prevent a UB @@ -284,11 +281,10 @@ TEST_P(CoarseWithMemoryStrategyTest, coarseProvider_wrong_params_5) { const size_t init_buffer_size = 20 * MB; - // Preallocate some memory - std::unique_ptr buffer(new char[init_buffer_size]); - void *buf = buffer.get(); + // preallocate some memory and initialize the vector with zeros + std::vector buffer(init_buffer_size, 0); + void *buf = (void *)buffer.data(); ASSERT_NE(buf, nullptr); - memset(buf, 0, init_buffer_size); coarse_memory_provider_params_t coarse_memory_provider_params; // make sure there are no undefined members - prevent a UB @@ -521,11 +517,10 @@ TEST_P(CoarseWithMemoryStrategyTest, coarseProvider_purge_no_upstream) { const size_t init_buffer_size = 20 * MB; - // Preallocate some memory - std::unique_ptr buffer(new char[init_buffer_size]); - void *buf = buffer.get(); + // preallocate some memory and initialize the vector with zeros + std::vector buffer(init_buffer_size, 0); + void *buf = (void *)buffer.data(); ASSERT_NE(buf, nullptr); - memset(buf, 0, init_buffer_size); coarse_memory_provider_params_t coarse_memory_provider_params; // make sure there are no undefined members - prevent a UB