From: Martin Quinson Date: Fri, 12 Aug 2016 21:53:34 +0000 (+0200) Subject: reduce the amount of unneed malloc X-Git-Tag: v3_14~566 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/91514c39f291c0f0667d3b5781573d1e373ce0b6 reduce the amount of unneed malloc --- diff --git a/src/surf/cpu_cas01.cpp b/src/surf/cpu_cas01.cpp index 8299e08506..d581269985 100644 --- a/src/surf/cpu_cas01.cpp +++ b/src/surf/cpu_cas01.cpp @@ -99,11 +99,11 @@ CpuCas01::CpuCas01(CpuCas01Model *model, simgrid::s4u::Host *host, std::vectorclear(); + speedPerPstate_.clear(); } std::vector * CpuCas01::getSpeedPeakList(){ - return speedPerPstate_; + return &speedPerPstate_; } bool CpuCas01::isUsed() diff --git a/src/surf/cpu_interface.cpp b/src/surf/cpu_interface.cpp index d9f658bd1c..a388ed01d1 100644 --- a/src/surf/cpu_interface.cpp +++ b/src/surf/cpu_interface.cpp @@ -144,20 +144,16 @@ Cpu::Cpu(Model *model, simgrid::s4u::Host *host, lmm_constraint_t constraint, xbt_assert(speed_.scale > 0, "Speed of host %s must be >0", host->name().c_str()); // Copy the power peak array: - speedPerPstate_ = new std::vector(); unsigned long n = speedPerPstate->size(); for (unsigned long i = 0; i != n; ++i) { double value = speedPerPstate->at(i); - speedPerPstate_->push_back(value); + speedPerPstate_.push_back(value); } xbt_assert(model == surf_cpu_model_pm || core==1, "Currently, VM cannot be multicore"); } -Cpu::~Cpu() -{ - delete speedPerPstate_; -} +Cpu::~Cpu() = default; double Cpu::getPstateSpeedCurrent() { @@ -166,17 +162,16 @@ double Cpu::getPstateSpeedCurrent() int Cpu::getNbPStates() { - return speedPerPstate_->size(); + return speedPerPstate_.size(); } void Cpu::setPState(int pstate_index) { - std::vector *plist = speedPerPstate_; - xbt_assert(pstate_index <= static_cast(plist->size()), + xbt_assert(pstate_index <= static_cast(speedPerPstate_.size()), "Invalid parameters for CPU %s (pstate %d > length of pstates %d)", getName(), pstate_index, - static_cast(plist->size())); + static_cast(speedPerPstate_.size())); - double new_peak_speed = plist->at(pstate_index); + double new_peak_speed = speedPerPstate_[pstate_index]; pstate_ = pstate_index; speed_.peak = new_peak_speed; @@ -190,10 +185,9 @@ int Cpu::getPState() double Cpu::getPstateSpeed(int pstate_index) { - std::vector *plist = speedPerPstate_; - xbt_assert((pstate_index <= static_cast(plist->size())), "Invalid parameters (pstate index out of bounds)"); + xbt_assert((pstate_index <= static_cast(speedPerPstate_.size())), "Invalid parameters (pstate index out of bounds)"); - return plist->at(pstate_index); + return speedPerPstate_[pstate_index]; } double Cpu::getSpeed(double load) diff --git a/src/surf/cpu_interface.hpp b/src/surf/cpu_interface.hpp index c1379c0016..26d371d906 100644 --- a/src/surf/cpu_interface.hpp +++ b/src/surf/cpu_interface.hpp @@ -133,8 +133,8 @@ public: int coresAmount_ = 1; simgrid::s4u::Host* host_; - std::vector *speedPerPstate_ = nullptr; /*< List of supported CPU capacities (pstate related) */ - int pstate_ = 0; /*< Current pstate (index in the speedPeakList)*/ + std::vector speedPerPstate_; /*< List of supported CPU capacities (pstate related) */ + int pstate_ = 0; /*< Current pstate (index in the speedPeakList)*/ public: virtual void setStateTrace(tmgr_trace_t trace); /*< setup the trace file with states events (ON or OFF). Trace must contain boolean values (0 or 1). */