From f35ba3f5fdbc8394864863bca70d5b31fa582cfe Mon Sep 17 00:00:00 2001 From: couriersud Date: Sat, 14 May 2016 15:17:21 +0200 Subject: More automatic memory handling. (nw) --- src/lib/netlist/plib/pstate.cpp | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) (limited to 'src/lib/netlist/plib/pstate.cpp') diff --git a/src/lib/netlist/plib/pstate.cpp b/src/lib/netlist/plib/pstate.cpp index d6ff433e388..aa5d7b7bae2 100644 --- a/src/lib/netlist/plib/pstate.cpp +++ b/src/lib/netlist/plib/pstate.cpp @@ -13,7 +13,7 @@ pstate_manager_t::pstate_manager_t() pstate_manager_t::~pstate_manager_t() { - m_save.clear_and_free(); + m_save.clear(); } @@ -36,24 +36,20 @@ ATTR_COLD void pstate_manager_t::save_state_ptr(const pstring &stname, const pst "DT_FLOAT" }; - pstate_entry_t *p = palloc(pstate_entry_t(stname, dt, owner, size, count, ptr, is_ptr)); - m_save.push_back(p); + auto p = std::make_unique(stname, dt, owner, size, count, ptr, is_ptr); + m_save.push_back(std::move(p)); } ATTR_COLD void pstate_manager_t::remove_save_items(const void *owner) { - pstate_entry_t::list_t todelete; - - for (std::size_t i=0; i < m_save.size(); i++) + unsigned i = 0; + while (i < m_save.size()) { if (m_save[i]->m_owner == owner) - todelete.push_back(m_save[i]); - } - for (std::size_t i=0; i < todelete.size(); i++) - { - m_save.remove(todelete[i]); + m_save.remove_at(i); + else + i++; } - todelete.clear_and_free(); } ATTR_COLD void pstate_manager_t::pre_save() @@ -74,7 +70,7 @@ template<> ATTR_COLD void pstate_manager_t::save_item(pstate_callback_t &state, { //save_state_ptr(stname, DT_CUSTOM, 0, 1, &state); pstate_callback_t *state_p = &state; - pstate_entry_t *p = palloc(pstate_entry_t(stname, owner, state_p)); - m_save.push_back(p); + auto p = std::make_unique(stname, owner, state_p); + m_save.push_back(std::move(p)); state.register_state(*this, stname); } -- cgit v1.2.3-70-g09d2