在C++中使用设置容器是否使用课程需要释放内存?

发布于 2025-02-04 06:59:24 字数 1279 浏览 1 评论 0原文

class rfdevice_ams2_l9s_cn_qm13341_sub_MIPI_data_ag:public rfdevice_asm2_data
{
public:
  static rfdevice_asm2_data * get_instance();
  ***std::set<int> Band_Count;***
  bool THCH_NRCA = false;
  bool THCH_ENDC = false;
  bool THCH_LTE_LTECA = false;
  bool THCH_GSM = false;
  bool THCH_WCDMA = false;
  bool THCH_CDMA = false;
  int Band_res;
  void Count_Band(rfdevice_asm2_tuning_data_info *tuning_data, int ant_cur,  uint8 scenario);
  void port_cc();
  boolean Get_NR_NRCA(rfdevice_asm2_tuning_data_info *tuning_data, uint8 *port, uint8 scenario);
  boolean Get_LTE_SIGNLE(rfdevice_asm2_tuning_data_info *tuning_data, uint8 *port, uint8 scenario);
  void TECH_Judge(rfdevice_asm2_tuning_data_info *tuning_data, uint8 scenario);
  boolean port_cc(rfdevice_asm2_tuning_data_info *tuning_data, uint8 *port, uint8 scenario);
  boolean get_script(rfdevice_asm2_cfg_params_type *cfg, rfdevice_asm2_settings_type_u *settings);

 ~rfdevice_ams2_l9s_cn_qm13341_sub_MIPI_data_ag(void);  /*  Destructor  */

protected:
  rfdevice_ams2_l9s_cn_qm13341_sub_MIPI_data_ag(void);  /*  Constructor  */

private:
  static rfdevice_asm2_data *rfdevice_ams2_l9s_cn_qm13341_sub_data_ptr;
};

C ++类中的设置容器的使用是否需要发布内存? 例如,std :: set band_count在此处;我需要在破坏者中释放内存吗?

class rfdevice_ams2_l9s_cn_qm13341_sub_MIPI_data_ag:public rfdevice_asm2_data
{
public:
  static rfdevice_asm2_data * get_instance();
  ***std::set<int> Band_Count;***
  bool THCH_NRCA = false;
  bool THCH_ENDC = false;
  bool THCH_LTE_LTECA = false;
  bool THCH_GSM = false;
  bool THCH_WCDMA = false;
  bool THCH_CDMA = false;
  int Band_res;
  void Count_Band(rfdevice_asm2_tuning_data_info *tuning_data, int ant_cur,  uint8 scenario);
  void port_cc();
  boolean Get_NR_NRCA(rfdevice_asm2_tuning_data_info *tuning_data, uint8 *port, uint8 scenario);
  boolean Get_LTE_SIGNLE(rfdevice_asm2_tuning_data_info *tuning_data, uint8 *port, uint8 scenario);
  void TECH_Judge(rfdevice_asm2_tuning_data_info *tuning_data, uint8 scenario);
  boolean port_cc(rfdevice_asm2_tuning_data_info *tuning_data, uint8 *port, uint8 scenario);
  boolean get_script(rfdevice_asm2_cfg_params_type *cfg, rfdevice_asm2_settings_type_u *settings);

 ~rfdevice_ams2_l9s_cn_qm13341_sub_MIPI_data_ag(void);  /*  Destructor  */

protected:
  rfdevice_ams2_l9s_cn_qm13341_sub_MIPI_data_ag(void);  /*  Constructor  */

private:
  static rfdevice_asm2_data *rfdevice_ams2_l9s_cn_qm13341_sub_data_ptr;
};

Does the use of set containers in c++ classes need to release memory?
For example, std::set Band_Count in here;Do I need to release memory in the destructor?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

安穩 2025-02-11 06:59:24

C ++具有破坏者,应该清除所有内存。对于C ++库中的(模板)类,总是如此。

呼叫set :: clear()在驱动器运行之前是一种从集合中删除所有对象的方法,从而释放用于包含对象的内存。 set :: size()之后为零。这确实意味着仍然需要一个非常非常的非常记忆,以记录一个零元素的事实。少量的簿记是sizeof(std :: set&lt; int&gt;)

std :: set&lt; yourClass&gt; :: clear()将调用yourClass的击路仪,以便收回内存。但是int没有破坏者(不是类),因此std :: set&lt; :: clear()更简单。

C++ has destructors, which should clear all memory. For the (template) classes in the C++ library, that's always the case.

Calling set::clear() before the destructor runs is a way to remove all objects from the set, releasing the memory used for the contained objects. set::size() will be zero afterwards. That does mean there is a very, very small amount of memory still needed, to record the fact that there are zero elements. This small amount of bookkeeping is sizeof(std::set<int>).

std::set<YourClass>::clear() will call the destructors of YourClass, so that memory too is reclaimed. But int has no destructors (it's not a class) so std::set<int>::clear() is a bit simpler.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文