Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
reduce the amount of unneed malloc
authorMartin Quinson <martin.quinson@loria.fr>
Fri, 12 Aug 2016 21:53:34 +0000 (23:53 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Fri, 12 Aug 2016 21:53:34 +0000 (23:53 +0200)
src/surf/cpu_cas01.cpp
src/surf/cpu_interface.cpp
src/surf/cpu_interface.hpp

index 8299e08..d581269 100644 (file)
@@ -99,11 +99,11 @@ CpuCas01::CpuCas01(CpuCas01Model *model, simgrid::s4u::Host *host, std::vector<d
 CpuCas01::~CpuCas01()
 {
   if (getModel() == surf_cpu_model_pm)
 CpuCas01::~CpuCas01()
 {
   if (getModel() == surf_cpu_model_pm)
-    speedPerPstate_->clear();
+    speedPerPstate_.clear();
 }
 
 std::vector<double> * CpuCas01::getSpeedPeakList(){
 }
 
 std::vector<double> * CpuCas01::getSpeedPeakList(){
-  return speedPerPstate_;
+  return &speedPerPstate_;
 }
 
 bool CpuCas01::isUsed()
 }
 
 bool CpuCas01::isUsed()
index d9f658b..a388ed0 100644 (file)
@@ -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:
   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<double>();
   unsigned long n = speedPerPstate->size();
   for (unsigned long i = 0; i != n; ++i) {
     double value = speedPerPstate->at(i);
   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");
 }
 
   }
 
   xbt_assert(model == surf_cpu_model_pm || core==1, "Currently, VM cannot be multicore");
 }
 
-Cpu::~Cpu()
-{
-  delete speedPerPstate_;
-}
+Cpu::~Cpu() = default;
 
 double Cpu::getPstateSpeedCurrent()
 {
 
 double Cpu::getPstateSpeedCurrent()
 {
@@ -166,17 +162,16 @@ double Cpu::getPstateSpeedCurrent()
 
 int Cpu::getNbPStates()
 {
 
 int Cpu::getNbPStates()
 {
-  return speedPerPstate_->size();
+  return speedPerPstate_.size();
 }
 
 void Cpu::setPState(int pstate_index)
 {
 }
 
 void Cpu::setPState(int pstate_index)
 {
-  std::vector<double> *plist = speedPerPstate_;
-  xbt_assert(pstate_index <= static_cast<int>(plist->size()),
+  xbt_assert(pstate_index <= static_cast<int>(speedPerPstate_.size()),
       "Invalid parameters for CPU %s (pstate %d > length of pstates %d)", getName(), pstate_index,
       "Invalid parameters for CPU %s (pstate %d > length of pstates %d)", getName(), pstate_index,
-      static_cast<int>(plist->size()));
+      static_cast<int>(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;
 
   pstate_ = pstate_index;
   speed_.peak = new_peak_speed;
 
@@ -190,10 +185,9 @@ int Cpu::getPState()
 
 double Cpu::getPstateSpeed(int pstate_index)
 {
 
 double Cpu::getPstateSpeed(int pstate_index)
 {
-  std::vector<double> *plist = speedPerPstate_;
-  xbt_assert((pstate_index <= static_cast<int>(plist->size())), "Invalid parameters (pstate index out of bounds)");
+  xbt_assert((pstate_index <= static_cast<int>(speedPerPstate_.size())), "Invalid parameters (pstate index out of bounds)");
 
 
-  return plist->at(pstate_index);
+  return speedPerPstate_[pstate_index];
 }
 
 double Cpu::getSpeed(double load)
 }
 
 double Cpu::getSpeed(double load)
index c1379c0..26d371d 100644 (file)
@@ -133,8 +133,8 @@ public:
   int coresAmount_ = 1;
   simgrid::s4u::Host* host_;
 
   int coresAmount_ = 1;
   simgrid::s4u::Host* host_;
 
-  std::vector<double> *speedPerPstate_ = nullptr; /*< List of supported CPU capacities (pstate related) */
-  int pstate_ = 0;                   /*< Current pstate (index in the speedPeakList)*/
+  std::vector<double> 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). */
 
 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). */