More memory timebombs removed. (nw)

This commit is contained in:
couriersud 2016-05-17 00:33:27 +02:00
parent d200744fbf
commit 9102271ef7
6 changed files with 25 additions and 12 deletions

View File

@ -148,9 +148,6 @@ NETLIB_RESET(logic_input)
NETLIB_STOP(logic_input) NETLIB_STOP(logic_input)
{ {
if (m_logic_family != nullptr)
if (!m_logic_family->m_is_static)
pfree(m_logic_family);
} }

View File

@ -321,8 +321,6 @@ public:
virtual ~netlist_base_factory_truthtable_t() virtual ~netlist_base_factory_truthtable_t()
{ {
if (!m_family->m_is_static)
pfree(m_family);
} }
pstring_vector_t m_desc; pstring_vector_t m_desc;

View File

@ -36,7 +36,6 @@ public:
m_high_V = 4.0; m_high_V = 4.0;
m_R_low = 1.0; m_R_low = 1.0;
m_R_high = 130.0; m_R_high = 130.0;
m_is_static = true;
} }
virtual powned_ptr<devices::nld_base_d_to_a_proxy> create_d_a_proxy(netlist_t &anetlist, const pstring &name, logic_output_t *proxied) const override virtual powned_ptr<devices::nld_base_d_to_a_proxy> create_d_a_proxy(netlist_t &anetlist, const pstring &name, logic_output_t *proxied) const override
{ {
@ -57,7 +56,6 @@ public:
m_high_V = 4.95; m_high_V = 4.95;
m_R_low = 10.0; m_R_low = 10.0;
m_R_high = 10.0; m_R_high = 10.0;
m_is_static = true;
} }
virtual powned_ptr<devices::nld_base_d_to_a_proxy> create_d_a_proxy(netlist_t &anetlist, const pstring &name, logic_output_t *proxied) const override virtual powned_ptr<devices::nld_base_d_to_a_proxy> create_d_a_proxy(netlist_t &anetlist, const pstring &name, logic_output_t *proxied) const override
{ {

View File

@ -352,7 +352,7 @@ namespace netlist
class logic_family_desc_t class logic_family_desc_t
{ {
public: public:
logic_family_desc_t() : m_is_static(false) {} logic_family_desc_t() {}
virtual ~logic_family_desc_t() {} virtual ~logic_family_desc_t() {}
virtual powned_ptr<devices::nld_base_d_to_a_proxy> create_d_a_proxy(netlist_t &anetlist, const pstring &name, virtual powned_ptr<devices::nld_base_d_to_a_proxy> create_d_a_proxy(netlist_t &anetlist, const pstring &name,
logic_output_t *proxied) const = 0; logic_output_t *proxied) const = 0;
@ -363,8 +363,6 @@ namespace netlist
nl_double m_high_V; nl_double m_high_V;
nl_double m_R_low; nl_double m_R_low;
nl_double m_R_high; nl_double m_R_high;
bool m_is_static;
}; };
class logic_family_t class logic_family_t
@ -1316,8 +1314,13 @@ namespace netlist
void print_stats() const; void print_stats() const;
pvector_t<powned_ptr<device_t>> m_devices; pvector_t<powned_ptr<device_t>> m_devices;
/* sole use is to manage lifetime of net objects */
net_t::list_t m_nets; net_t::list_t m_nets;
/* sole use is to manage lifetime of family objects */
std::vector<std::pair<pstring, std::unique_ptr<logic_family_desc_t>>> m_family_cache;
protected: protected:
#if (NL_KEEP_STATISTICS) #if (NL_KEEP_STATISTICS)

View File

@ -886,7 +886,11 @@ const logic_family_desc_t *setup_t::family_from_model(const pstring &model)
if (setup_t::model_value_str(map, "TYPE") == "CD4XXX") if (setup_t::model_value_str(map, "TYPE") == "CD4XXX")
return family_CD4XXX(); return family_CD4XXX();
logic_family_std_proxy_t *ret = palloc(logic_family_std_proxy_t); for (auto & e : netlist().m_family_cache)
if (e.first == model)
return e.second.get();
auto ret = make_unique_base<logic_family_desc_t, logic_family_std_proxy_t>();
ret->m_low_thresh_V = setup_t::model_value(map, "IVL"); ret->m_low_thresh_V = setup_t::model_value(map, "IVL");
ret->m_high_thresh_V = setup_t::model_value(map, "IVH"); ret->m_high_thresh_V = setup_t::model_value(map, "IVH");
@ -895,7 +899,13 @@ const logic_family_desc_t *setup_t::family_from_model(const pstring &model)
ret->m_R_low = setup_t::model_value(map, "ORL"); ret->m_R_low = setup_t::model_value(map, "ORL");
ret->m_R_high = setup_t::model_value(map, "ORH"); ret->m_R_high = setup_t::model_value(map, "ORH");
return ret; auto retp = ret.get();
printf("placing %s in cache\n", model.cstr());
//netlist().m_family_cache.push_back(std::pair<pstring, std::unique_ptr<logic_family_desc_t>>(model, std::move(ret)));
netlist().m_family_cache.emplace_back(model, std::move(ret));
return retp;
} }
static pstring model_string(model_map_t &map) static pstring model_string(model_map_t &map)

View File

@ -199,5 +199,12 @@ private:
bool m_is_owned; bool m_is_owned;
}; };
template<typename _BC, typename _DC, typename... _Args>
static std::unique_ptr<_BC> make_unique_base(_Args&&... __args)
{
std::unique_ptr<_BC> ret(new _DC(std::forward<_Args>(__args)...));
return ret;
}
#endif /* NL_UTIL_H_ */ #endif /* NL_UTIL_H_ */