From 90102c2bfcf98f842f66567c67cbccbd0ede1d2b Mon Sep 17 00:00:00 2001 From: Vijay Pai Date: Thu, 3 Nov 2016 11:41:19 -0700 Subject: Eliminate unnecessary uses of new[]/delete[] that can be replaced with vector Also start eliminating uses of plain-old delete that are not helpful --- test/cpp/qps/client.h | 7 ++----- test/cpp/qps/client_sync.cc | 12 +++--------- test/cpp/qps/driver.cc | 13 ++----------- 3 files changed, 7 insertions(+), 25 deletions(-) (limited to 'test/cpp/qps') diff --git a/test/cpp/qps/client.h b/test/cpp/qps/client.h index a8d125ad28..56bfa9fee1 100644 --- a/test/cpp/qps/client.h +++ b/test/cpp/qps/client.h @@ -163,10 +163,9 @@ class Client { MaybeStartRequests(); - // avoid std::vector for old compilers that expect a copy constructor if (reset) { - Histogram* to_merge = new Histogram[threads_.size()]; - StatusHistogram* to_merge_status = new StatusHistogram[threads_.size()]; + std::vector to_merge(threads_.size()); + std::vector to_merge_status(threads_.size()); for (size_t i = 0; i < threads_.size(); i++) { threads_[i]->BeginSwap(&to_merge[i], &to_merge_status[i]); @@ -177,8 +176,6 @@ class Client { latencies.Merge(to_merge[i]); MergeStatusHistogram(to_merge_status[i], &statuses); } - delete[] to_merge; - delete[] to_merge_status; timer_result = timer->Mark(); } else { // merge snapshots of each thread histogram diff --git a/test/cpp/qps/client_sync.cc b/test/cpp/qps/client_sync.cc index a88a24d89c..3f402b5c36 100644 --- a/test/cpp/qps/client_sync.cc +++ b/test/cpp/qps/client_sync.cc @@ -138,10 +138,7 @@ class SynchronousUnaryClient final : public SynchronousClient { class SynchronousStreamingClient final : public SynchronousClient { public: SynchronousStreamingClient(const ClientConfig& config) - : SynchronousClient(config) { - context_ = new grpc::ClientContext[num_threads_]; - stream_ = new std::unique_ptr< - grpc::ClientReaderWriter>[num_threads_]; + : SynchronousClient(config), context_(num_threads_), stream_(num_threads_) { for (size_t thread_idx = 0; thread_idx < num_threads_; thread_idx++) { auto* stub = channels_[thread_idx % channels_.size()].get_stub(); stream_[thread_idx] = stub->StreamingCall(&context_[thread_idx]); @@ -161,8 +158,6 @@ class SynchronousStreamingClient final : public SynchronousClient { } } } - delete[] stream_; - delete[] context_; } bool ThreadFunc(HistogramEntry* entry, size_t thread_idx) override { @@ -182,9 +177,8 @@ class SynchronousStreamingClient final : public SynchronousClient { private: // These are both conceptually std::vector but cannot be for old compilers // that expect contained classes to support copy constructors - grpc::ClientContext* context_; - std::unique_ptr>* - stream_; + std::vector context_; + std::vector>> stream_; }; std::unique_ptr CreateSynchronousUnaryClient( diff --git a/test/cpp/qps/driver.cc b/test/cpp/qps/driver.cc index a440341ccf..2f343d3688 100644 --- a/test/cpp/qps/driver.cc +++ b/test/cpp/qps/driver.cc @@ -262,10 +262,7 @@ std::unique_ptr RunScenario( workers.resize(num_clients + num_servers); // Start servers - using runsc::ServerData; - // servers is array rather than std::vector to avoid gcc-4.4 issues - // where class contained in std::vector must have a copy constructor - auto* servers = new ServerData[num_servers]; + std::vector servers(num_servers); for (size_t i = 0; i < num_servers; i++) { gpr_log(GPR_INFO, "Starting server on %s (worker #%" PRIuPTR ")", workers[i].c_str(), i); @@ -328,10 +325,7 @@ std::unique_ptr RunScenario( // Targets are all set by now result_client_config = client_config; // Start clients - using runsc::ClientData; - // clients is array rather than std::vector to avoid gcc-4.4 issues - // where class contained in std::vector must have a copy constructor - auto* clients = new ClientData[num_clients]; + std::vector clients(num_clients); size_t channels_allocated = 0; for (size_t i = 0; i < num_clients; i++) { const auto& worker = workers[i + num_servers]; @@ -501,7 +495,6 @@ std::unique_ptr RunScenario( s.error_message().c_str()); } } - delete[] clients; merged_latencies.FillProto(result->mutable_latencies()); for (std::unordered_map::iterator it = merged_statuses.begin(); @@ -544,8 +537,6 @@ std::unique_ptr RunScenario( } } - delete[] servers; - postprocess_scenario_result(result.get()); return result; } -- cgit v1.2.3