Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
reduce the amount of mallocs (and plug a memleak)
authorMartin Quinson <martin.quinson@loria.fr>
Sun, 14 Aug 2016 21:26:41 +0000 (23:26 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Sun, 14 Aug 2016 21:26:41 +0000 (23:26 +0200)
src/bindings/lua/lua_platf.cpp
src/surf/cpu_interface.cpp
src/surf/instr_routing.cpp
src/surf/sg_platf.cpp
src/surf/xml/platf_private.hpp
src/surf/xml/surfxml_sax_cb.cpp

index fc3b0a8..ca263d2 100644 (file)
@@ -163,9 +163,9 @@ int console_add_host(lua_State *L) {
   lua_ensure(type == LUA_TSTRING || type == LUA_TNUMBER,
       "Attribute 'speed' must be specified for host and must either be a string (in the correct format; check documentation) or a number.");
   if (type == LUA_TNUMBER)
-    host.speed_per_pstate->push_back(lua_tointeger(L, -1));
+    host.speed_per_pstate.push_back(lua_tointeger(L, -1));
   else // LUA_TSTRING
-    host.speed_per_pstate->push_back(surf_parse_get_speed(lua_tostring(L, -1), "speed of host", host.id));
+    host.speed_per_pstate.push_back(surf_parse_get_speed(lua_tostring(L, -1), "speed of host", host.id));
   lua_pop(L, 1);
 
   // get core
index a388ed0..3427096 100644 (file)
@@ -144,9 +144,7 @@ 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:
-  unsigned long n = speedPerPstate->size();
-  for (unsigned long i = 0; i != n; ++i) {
-    double value = speedPerPstate->at(i);
+  for (double value : *speedPerPstate) {
     speedPerPstate_.push_back(value);
   }
 
index 92d32b3..7d75080 100644 (file)
@@ -265,7 +265,7 @@ void sg_instr_new_host(sg_platf_host_cbarg_t host)
       speed = PJ_type_variable_new ("power", nullptr, container->type);
     }
 
-    double current_speed_state = host->speed_per_pstate->at(host->pstate);
+    double current_speed_state = host->speed_per_pstate[host->pstate];
     new_pajeSetVariable (0, container, speed, current_speed_state);
   }
   if (TRACE_uncategorized()){
index 7c8b90e..b6b2ec2 100644 (file)
@@ -148,7 +148,7 @@ void sg_platf_new_host(sg_platf_host_cbarg_t host)
     h->extension_set(COORD_HOST_LEVEL, (void *) ctn);
   }
 
-  simgrid::surf::Cpu *cpu = surf_cpu_model_pm->createCpu( h, host->speed_per_pstate, host->core_amount);
+  simgrid::surf::Cpu *cpu = surf_cpu_model_pm->createCpu( h, &host->speed_per_pstate, host->core_amount);
   if (host->state_trace)
     cpu->setStateTrace(host->state_trace);
   if (host->speed_trace)
@@ -301,8 +301,7 @@ void sg_platf_new_cluster(sg_platf_cluster_cbarg_t cluster)
       }
     }
 
-    host.speed_per_pstate = new std::vector<double>();
-    host.speed_per_pstate->push_back(cluster->speed);
+    host.speed_per_pstate.push_back(cluster->speed);
     host.pstate = 0;
     host.core_amount = cluster->core_amount;
     host.coord = "";
@@ -421,10 +420,8 @@ void sg_platf_new_cabinet(sg_platf_cabinet_cbarg_t cabinet)
     host.pstate           = 0;
     host.core_amount      = 1;
     host.id               = hostname;
-    host.speed_per_pstate = new std::vector<double>();
-    host.speed_per_pstate->push_back(cabinet->speed);
+    host.speed_per_pstate.push_back(cabinet->speed);
     sg_platf_new_host(&host);
-    delete host.speed_per_pstate;
 
     s_sg_platf_link_cbarg_t link;
     memset(&link, 0, sizeof(link));
@@ -666,14 +663,12 @@ void sg_platf_new_peer(sg_platf_peer_cbarg_t peer)
   memset(&host, 0, sizeof(host));
   host.id = host_id;
 
-  host.speed_per_pstate = new std::vector<double>();
-  host.speed_per_pstate->push_back(peer->speed);
+  host.speed_per_pstate.push_back(peer->speed);
   host.pstate = 0;
   host.speed_trace = peer->availability_trace;
   host.state_trace = peer->state_trace;
   host.core_amount = 1;
   sg_platf_new_host(&host);
-  delete host.speed_per_pstate;
 
   s_sg_platf_link_cbarg_t link;
   memset(&link, 0, sizeof(link));
index 0a5d3eb..976fa05 100644 (file)
@@ -42,7 +42,7 @@ typedef enum {
 
 typedef struct {
   const char* id;
-  std::vector<double> *speed_per_pstate;
+  std::vector<double> speed_per_pstate;
   int pstate;
   int core_amount;
   tmgr_trace_t speed_trace;
index e81955b..e426c40 100644 (file)
@@ -456,10 +456,9 @@ void ETag_surfxml_host()    {
 
   buf = A_surfxml_host_speed;
   XBT_DEBUG("Buffer: %s", buf);
-  host.speed_per_pstate = new std::vector<double>();
   if (strchr(buf, ',') == nullptr){
     double speed = surf_parse_get_speed(A_surfxml_host_speed,"speed of host", host.id);
-    host.speed_per_pstate->push_back(speed);
+    host.speed_per_pstate.push_back(speed);
   }
   else {
     xbt_dynar_t pstate_list = xbt_str_split(buf, ",");
@@ -468,7 +467,7 @@ void ETag_surfxml_host()    {
     xbt_dynar_foreach(pstate_list, i, speed_str) {
       xbt_str_trim(speed_str, nullptr);
       double speed = surf_parse_get_speed(speed_str,"speed of host", host.id);
-      host.speed_per_pstate->push_back(speed);
+      host.speed_per_pstate.push_back(speed);
       XBT_DEBUG("Speed value: %f", speed);
     }
     xbt_dynar_free(&pstate_list);
@@ -482,7 +481,6 @@ void ETag_surfxml_host()    {
   host.coord       = A_surfxml_host_coordinates;
 
   sg_platf_new_host(&host);
-  delete host.speed_per_pstate;
   current_property_set = nullptr;
 }