Skip to content

Commit 0aaee44

Browse files
committed
Use std::vector<char> instead of std::unique_ptr<char[]>
Use std::vector<char> instead of std::unique_ptr<char[]> because we do not need to use memset(0) in this case. Signed-off-by: Lukasz Dorau <[email protected]>
1 parent 5b89497 commit 0aaee44

File tree

2 files changed

+18
-24
lines changed

2 files changed

+18
-24
lines changed

test/disjointCoarseMallocPool.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -395,11 +395,10 @@ TEST_P(CoarseWithMemoryStrategyTest, disjointCoarseMMapPool_random) {
395395

396396
const size_t init_buffer_size = 200 * MB;
397397

398-
// Preallocate some memory
399-
std::unique_ptr<char[]> buffer(new char[init_buffer_size]);
400-
void *buf = buffer.get();
398+
// preallocate some memory and initialize the vector with zeros
399+
std::vector<char> buffer(init_buffer_size, 0);
400+
void *buf = buffer.data();
401401
ASSERT_NE(buf, nullptr);
402-
memset(buf, 0, init_buffer_size);
403402

404403
const unsigned char alloc_check_val = 11;
405404

test/provider_coarse.cpp

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,10 @@ TEST_F(test, disjointCoarseMallocPool_name_no_upstream) {
8686

8787
const size_t init_buffer_size = 20 * MB;
8888

89-
// Preallocate some memory
90-
std::unique_ptr<char[]> buffer(new char[init_buffer_size]);
91-
void *buf = buffer.get();
89+
// preallocate some memory and initialize the vector with zeros
90+
std::vector<char> buffer(init_buffer_size, 0);
91+
void *buf = buffer.data();
9292
ASSERT_NE(buf, nullptr);
93-
memset(buf, 0, init_buffer_size);
9493

9594
coarse_memory_provider_params_t coarse_memory_provider_params;
9695
// make sure there are no undefined members - prevent a UB
@@ -160,11 +159,10 @@ TEST_P(CoarseWithMemoryStrategyTest, disjointCoarseMallocPool_wrong_params_1) {
160159

161160
const size_t init_buffer_size = 20 * MB;
162161

163-
// Preallocate some memory
164-
std::unique_ptr<char[]> buffer(new char[init_buffer_size]);
165-
void *buf = buffer.get();
162+
// preallocate some memory and initialize the vector with zeros
163+
std::vector<char> buffer(init_buffer_size, 0);
164+
void *buf = buffer.data();
166165
ASSERT_NE(buf, nullptr);
167-
memset(buf, 0, init_buffer_size);
168166

169167
coarse_memory_provider_params_t coarse_memory_provider_params;
170168
// make sure there are no undefined members - prevent a UB
@@ -224,11 +222,10 @@ TEST_P(CoarseWithMemoryStrategyTest, disjointCoarseMallocPool_wrong_params_3) {
224222

225223
const size_t init_buffer_size = 20 * MB;
226224

227-
// Preallocate some memory
228-
std::unique_ptr<char[]> buffer(new char[init_buffer_size]);
229-
void *buf = buffer.get();
225+
// preallocate some memory and initialize the vector with zeros
226+
std::vector<char> buffer(init_buffer_size, 0);
227+
void *buf = buffer.data();
230228
ASSERT_NE(buf, nullptr);
231-
memset(buf, 0, init_buffer_size);
232229

233230
coarse_memory_provider_params_t coarse_memory_provider_params;
234231
// make sure there are no undefined members - prevent a UB
@@ -285,11 +282,10 @@ TEST_P(CoarseWithMemoryStrategyTest, disjointCoarseMallocPool_wrong_params_5) {
285282

286283
const size_t init_buffer_size = 20 * MB;
287284

288-
// Preallocate some memory
289-
std::unique_ptr<char[]> buffer(new char[init_buffer_size]);
290-
void *buf = buffer.get();
285+
// preallocate some memory and initialize the vector with zeros
286+
std::vector<char> buffer(init_buffer_size, 0);
287+
void *buf = buffer.data();
291288
ASSERT_NE(buf, nullptr);
292-
memset(buf, 0, init_buffer_size);
293289

294290
coarse_memory_provider_params_t coarse_memory_provider_params;
295291
// make sure there are no undefined members - prevent a UB
@@ -524,11 +520,10 @@ TEST_P(CoarseWithMemoryStrategyTest,
524520

525521
const size_t init_buffer_size = 20 * MB;
526522

527-
// Preallocate some memory
528-
std::unique_ptr<char[]> buffer(new char[init_buffer_size]);
529-
void *buf = buffer.get();
523+
// preallocate some memory and initialize the vector with zeros
524+
std::vector<char> buffer(init_buffer_size, 0);
525+
void *buf = buffer.data();
530526
ASSERT_NE(buf, nullptr);
531-
memset(buf, 0, init_buffer_size);
532527

533528
coarse_memory_provider_params_t coarse_memory_provider_params;
534529
// make sure there are no undefined members - prevent a UB

0 commit comments

Comments
 (0)