From 090d093557a63a3ba94dfedbb956d4158f99a223 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E5=A5=87=E5=8F=AF?= Date: Mon, 10 Sep 2018 20:15:19 +0800 Subject: [PATCH] use shared ptr to manage coeff tab memory --- mace/kernels/resize_bicubic.h | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/mace/kernels/resize_bicubic.h b/mace/kernels/resize_bicubic.h index 72458041..f8953e89 100644 --- a/mace/kernels/resize_bicubic.h +++ b/mace/kernels/resize_bicubic.h @@ -33,25 +33,27 @@ namespace kernels { static const int64_t kTableSize = (1 << 10); -inline const float *InitCoeffsTable() { +inline const std::shared_ptr InitCoeffsTable() { // Allocate and initialize coefficients table using Bicubic // convolution algorithm. // https://en.wikipedia.org/wiki/Bicubic_interpolation - float *coeffs_tab = new float[(kTableSize + 1) * 2]; + auto coeffs_tab = std::shared_ptr(new float[(kTableSize + 1) * 2], + std::default_delete()); + float *coeffs_tab_ptr = coeffs_tab.get(); static const double A = -0.75; for (int i = 0; i <= kTableSize; ++i) { float x = i * 1.0 / kTableSize; - coeffs_tab[i * 2] = ((A + 2) * x - (A + 3)) * x * x + 1; + coeffs_tab_ptr[i * 2] = ((A + 2) * x - (A + 3)) * x * x + 1; x += 1.0; - coeffs_tab[i * 2 + 1] = ((A * x - 5 * A) * x + 8 * A) * x - 4 * A; + coeffs_tab_ptr[i * 2 + 1] = ((A * x - 5 * A) * x + 8 * A) * x - 4 * A; } return coeffs_tab; } inline const float *GetCoeffsTable() { // Static so that we initialize it on first use - static const float *coeffs_tab = InitCoeffsTable(); - return coeffs_tab; + static const std::shared_ptr coeffs_tab = InitCoeffsTable(); + return coeffs_tab.get(); } inline int64_t Bound(int64_t val, int64_t limit) { -- GitLab