Skip to content

Commit 1b3d694

Browse files
authored
Merge pull request #828 from ldorau/Use_std_vector_char_instead_of_std_unique_ptr_char
Use `std::vector<char>` instead of `std::unique_ptr<char[]>`
2 parents 80e55db + a4080b4 commit 1b3d694

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 = (void *)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
@@ -85,11 +85,10 @@ TEST_F(test, coarseProvider_name_no_upstream) {
8585

8686
const size_t init_buffer_size = 20 * MB;
8787

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

9493
coarse_memory_provider_params_t coarse_memory_provider_params;
9594
// make sure there are no undefined members - prevent a UB
@@ -159,11 +158,10 @@ TEST_P(CoarseWithMemoryStrategyTest, coarseProvider_wrong_params_1) {
159158

160159
const size_t init_buffer_size = 20 * MB;
161160

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

168166
coarse_memory_provider_params_t coarse_memory_provider_params;
169167
// make sure there are no undefined members - prevent a UB
@@ -223,11 +221,10 @@ TEST_P(CoarseWithMemoryStrategyTest, coarseProvider_wrong_params_3) {
223221

224222
const size_t init_buffer_size = 20 * MB;
225223

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

232229
coarse_memory_provider_params_t coarse_memory_provider_params;
233230
// make sure there are no undefined members - prevent a UB
@@ -284,11 +281,10 @@ TEST_P(CoarseWithMemoryStrategyTest, coarseProvider_wrong_params_5) {
284281

285282
const size_t init_buffer_size = 20 * MB;
286283

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

293289
coarse_memory_provider_params_t coarse_memory_provider_params;
294290
// make sure there are no undefined members - prevent a UB
@@ -521,11 +517,10 @@ TEST_P(CoarseWithMemoryStrategyTest, coarseProvider_purge_no_upstream) {
521517

522518
const size_t init_buffer_size = 20 * MB;
523519

524-
// Preallocate some memory
525-
std::unique_ptr<char[]> buffer(new char[init_buffer_size]);
526-
void *buf = buffer.get();
520+
// preallocate some memory and initialize the vector with zeros
521+
std::vector<char> buffer(init_buffer_size, 0);
522+
void *buf = (void *)buffer.data();
527523
ASSERT_NE(buf, nullptr);
528-
memset(buf, 0, init_buffer_size);
529524

530525
coarse_memory_provider_params_t coarse_memory_provider_params;
531526
// make sure there are no undefined members - prevent a UB

0 commit comments

Comments
 (0)