From 83ead44d45775e4a31d303a735116cf8c3a8373d Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Sun, 16 Jan 2022 14:04:09 -0800 Subject: [PATCH] mingle bundle: replace a 'unique_ptr' with a 'vector' Similar to the prior commit, when the `std::unique_ptr` usage was added here in 176c8a163a951a2b801956ed4a00da05603e3a06, I was incorrectly too focused on preserving the previous property of this being a heap-allocated array. This is not necessary, and using a `std::vector` instead allows more flexibility. E.g. depending on the `std::vector` implementation, it could choose to allocate this array on the stack instead of the heap. --- cmd/mingle/minglemain.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/cmd/mingle/minglemain.cpp b/cmd/mingle/minglemain.cpp index 42f1990aa..018359211 100644 --- a/cmd/mingle/minglemain.cpp +++ b/cmd/mingle/minglemain.cpp @@ -16,7 +16,6 @@ #include #include #include -#include #include #include @@ -441,7 +440,7 @@ bundle (Agraph_t* g, opts_t* opts) ia = A->ia; ja = A->ja; nz = A->nz; - std::unique_ptr xx(new double[nz * 4]); + std::vector xx(nz * 4); nz = 0; dim = 4; for (i = 0; i < A->m; i++){ @@ -458,12 +457,12 @@ bundle (Agraph_t* g, opts_t* opts) if (Verbose) std::cerr << "n = " << A->m << " nz = " << nz << '\n'; - B = nearest_neighbor_graph(nz, MIN(opts->nneighbors, nz), xx.get(), eps); + B = nearest_neighbor_graph(nz, MIN(opts->nneighbors, nz), xx.data(), eps); SparseMatrix_delete(A); A = B; free(x); - x = xx.get(); + x = xx.data(); dim = 2; -- 2.40.0