From 0126ecb3e25295edc0768d20223d1358e330c622 Mon Sep 17 00:00:00 2001 From: Carloschi7 <92332381+Carloschi7@users.noreply.github.com> Date: Sat, 18 Dec 2021 07:31:09 +0100 Subject: [PATCH] added std::vector instead of V* (#5902) --- src/common/linear_disk_cache.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/common/linear_disk_cache.h b/src/common/linear_disk_cache.h index 94c695163..61e4bd217 100644 --- a/src/common/linear_disk_cache.h +++ b/src/common/linear_disk_cache.h @@ -5,6 +5,7 @@ #pragma once #include +#include #include "common/common_types.h" // defined in Version.cpp @@ -66,7 +67,7 @@ public: // good header, read some key/value pairs K key; - V* value = nullptr; + std::vector value; u32 value_size; u32 entry_number; @@ -78,13 +79,13 @@ public: if (next_extent > file_size) break; - delete[] value; - value = new V[value_size]; + value.clear(); + value.resize(value_size); // read key/value and pass to reader - if (Read(&key) && Read(value, value_size) && Read(&entry_number) && + if (Read(&key) && Read(value.data(), value_size) && Read(&entry_number) && entry_number == m_num_entries + 1) { - reader.Read(key, value, value_size); + reader.Read(key, value.data(), value_size); } else { break; } @@ -95,7 +96,7 @@ public: m_file.seekp(last_pos); m_file.clear(); - delete[] value; + value.clear(); return m_num_entries; }