Skip to content

Commit 785baae

Browse files
committed
fix: avoid using implicit new operator to manage memory
Signed-off-by: syaojun <libevent@yeah.net>
1 parent 080a2f6 commit 785baae

2 files changed

Lines changed: 15 additions & 13 deletions

File tree

cpp/src/graphar/label.cc

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
#include <cassert>
2323
#include <cstring>
2424
#include <memory>
25+
#include <vector>
26+
27+
namespace graphar {
2528

2629
/// Read a parquet file by ParquetReader & get valid indices
2730
/// The first column_num labels are concerned.
@@ -44,9 +47,9 @@ int read_parquet_file_and_get_valid_indices(
4447

4548
// Initialize the column row counts
4649
std::vector<int> col_row_counts(num_columns, 0);
47-
bool** value = new bool*[num_columns];
50+
std::vector<std::unique_ptr<bool[]>> value(num_columns);
4851
for (int i = 0; i < num_columns; i++) {
49-
value[i] = new bool[row_num];
52+
value[i] = std::make_unique<bool[]>(row_num);
5053
}
5154

5255
// Iterate over all the RowGroups in the file
@@ -73,9 +76,9 @@ int read_parquet_file_and_get_valid_indices(
7376
// Read BATCH_SIZE values at a time. The number of rows read is
7477
// returned. values_read contains the number of non-null rows
7578

76-
rows_read = bool_reader->ReadBatch(BATCH_SIZE, nullptr, nullptr,
77-
value[k] + col_row_counts[col_id],
78-
&values_read);
79+
rows_read = bool_reader->ReadBatch(
80+
BATCH_SIZE, nullptr, nullptr,
81+
value[k].get() + col_row_counts[col_id], &values_read);
7982

8083
// There are no NULL values in the rows written
8184
col_row_counts[col_id] += rows_read;
@@ -99,11 +102,7 @@ int read_parquet_file_and_get_valid_indices(
99102
}
100103
}
101104

102-
// destroy the allocated space
103-
for (int i = 0; i < num_columns; i++) {
104-
delete[] value[i];
105-
}
106-
delete[] value;
107-
108105
return count;
109106
}
107+
108+
} // namespace graphar

cpp/src/graphar/label.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626
#include <parquet/api/writer.h>
2727
#include <parquet/properties.h>
2828

29-
#include <iostream>
30-
#include <set>
29+
#include <functional>
3130
#include <vector>
3231

3332
using parquet::ConvertedType;
@@ -37,6 +36,8 @@ using parquet::Type;
3736
using parquet::schema::GroupNode;
3837
using parquet::schema::PrimitiveNode;
3938

39+
namespace graphar {
40+
4041
constexpr int BATCH_SIZE = 1024; // the batch size
4142

4243
/// The query type
@@ -60,4 +61,6 @@ int read_parquet_file_and_get_valid_indices(
6061
uint64_t* bitmap = nullptr,
6162
const QUERY_TYPE query_type = QUERY_TYPE::COUNT);
6263

64+
} // namespace graphar
65+
6366
#endif // CPP_SRC_GRAPHAR_LABEL_H_

0 commit comments

Comments
 (0)