From d469f50b8c4288a559b6e1c561b1c0e6efbec864 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Sun, 14 Aug 2016 23:26:41 +0200 Subject: [PATCH] reduce the amount of mallocs (and plug a memleak) --- src/bindings/lua/lua_platf.cpp | 4 ++-- src/surf/cpu_interface.cpp | 4 +--- src/surf/instr_routing.cpp | 2 +- src/surf/sg_platf.cpp | 13 ++++--------- src/surf/xml/platf_private.hpp | 2 +- src/surf/xml/surfxml_sax_cb.cpp | 6 ++---- 6 files changed, 11 insertions(+), 20 deletions(-) diff --git a/src/bindings/lua/lua_platf.cpp b/src/bindings/lua/lua_platf.cpp index fc3b0a8b1d..ca263d2da6 100644 --- a/src/bindings/lua/lua_platf.cpp +++ b/src/bindings/lua/lua_platf.cpp @@ -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 diff --git a/src/surf/cpu_interface.cpp b/src/surf/cpu_interface.cpp index a388ed01d1..34270964df 100644 --- a/src/surf/cpu_interface.cpp +++ b/src/surf/cpu_interface.cpp @@ -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); } diff --git a/src/surf/instr_routing.cpp b/src/surf/instr_routing.cpp index 92d32b3d55..7d750800ea 100644 --- a/src/surf/instr_routing.cpp +++ b/src/surf/instr_routing.cpp @@ -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()){ diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index 7c8b90e828..b6b2ec26df 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -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(); - 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(); - 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(); - 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)); diff --git a/src/surf/xml/platf_private.hpp b/src/surf/xml/platf_private.hpp index 0a5d3ebfb8..976fa05ba4 100644 --- a/src/surf/xml/platf_private.hpp +++ b/src/surf/xml/platf_private.hpp @@ -42,7 +42,7 @@ typedef enum { typedef struct { const char* id; - std::vector *speed_per_pstate; + std::vector speed_per_pstate; int pstate; int core_amount; tmgr_trace_t speed_trace; diff --git a/src/surf/xml/surfxml_sax_cb.cpp b/src/surf/xml/surfxml_sax_cb.cpp index e81955b2c4..e426c40063 100644 --- a/src/surf/xml/surfxml_sax_cb.cpp +++ b/src/surf/xml/surfxml_sax_cb.cpp @@ -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(); 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; } -- 2.20.1