This is an automated email from the ASF dual-hosted git repository.
yangxk1 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-graphar.git
The following commit(s) were added to refs/heads/main by this push:
new 70b997f1 fix: avoid using implicit new operator to manage memory (#915)
70b997f1 is described below
commit 70b997f15b7d451f637baf9314973a7f8d2d970f
Author: Jason <[email protected]>
AuthorDate: Thu May 7 20:31:48 2026 +0800
fix: avoid using implicit new operator to manage memory (#915)
Signed-off-by: syaojun <[email protected]>
---
cpp/src/graphar/label.cc | 21 ++++++++++-----------
cpp/src/graphar/label.h | 7 +++++--
2 files changed, 15 insertions(+), 13 deletions(-)
diff --git a/cpp/src/graphar/label.cc b/cpp/src/graphar/label.cc
index 64f3c1ab..83f597fc 100644
--- a/cpp/src/graphar/label.cc
+++ b/cpp/src/graphar/label.cc
@@ -22,6 +22,9 @@
#include <cassert>
#include <cstring>
#include <memory>
+#include <vector>
+
+namespace graphar {
/// Read a parquet file by ParquetReader & get valid indices
/// The first column_num labels are concerned.
@@ -44,9 +47,9 @@ int read_parquet_file_and_get_valid_indices(
// Initialize the column row counts
std::vector<int> col_row_counts(num_columns, 0);
- bool** value = new bool*[num_columns];
+ std::vector<std::unique_ptr<bool[]>> value(num_columns);
for (int i = 0; i < num_columns; i++) {
- value[i] = new bool[row_num];
+ value[i] = std::make_unique<bool[]>(row_num);
}
// Iterate over all the RowGroups in the file
@@ -73,9 +76,9 @@ int read_parquet_file_and_get_valid_indices(
// Read BATCH_SIZE values at a time. The number of rows read is
// returned. values_read contains the number of non-null rows
- rows_read = bool_reader->ReadBatch(BATCH_SIZE, nullptr, nullptr,
- value[k] + col_row_counts[col_id],
- &values_read);
+ rows_read = bool_reader->ReadBatch(
+ BATCH_SIZE, nullptr, nullptr,
+ value[k].get() + col_row_counts[col_id], &values_read);
// There are no NULL values in the rows written
col_row_counts[col_id] += rows_read;
@@ -99,11 +102,7 @@ int read_parquet_file_and_get_valid_indices(
}
}
- // destroy the allocated space
- for (int i = 0; i < num_columns; i++) {
- delete[] value[i];
- }
- delete[] value;
-
return count;
}
+
+} // namespace graphar
diff --git a/cpp/src/graphar/label.h b/cpp/src/graphar/label.h
index ec69e626..0429d93f 100644
--- a/cpp/src/graphar/label.h
+++ b/cpp/src/graphar/label.h
@@ -26,8 +26,7 @@
#include <parquet/api/writer.h>
#include <parquet/properties.h>
-#include <iostream>
-#include <set>
+#include <functional>
#include <vector>
using parquet::ConvertedType;
@@ -37,6 +36,8 @@ using parquet::Type;
using parquet::schema::GroupNode;
using parquet::schema::PrimitiveNode;
+namespace graphar {
+
constexpr int BATCH_SIZE = 1024; // the batch size
/// The query type
@@ -60,4 +61,6 @@ int read_parquet_file_and_get_valid_indices(
uint64_t* bitmap = nullptr,
const QUERY_TYPE query_type = QUERY_TYPE::COUNT);
+} // namespace graphar
+
#endif // CPP_SRC_GRAPHAR_LABEL_H_
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]