加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – std :: string :: clear和std :: list :: clear清除内存中

发布时间:2020-12-16 05:38:50 所属栏目:百科 来源:网络整理
导读:在string :: clear函数的描述中,它说: clear: Erases the contents of the string,which becomes an empty string (with a length of 0 characters). 在list :: clear函数的描述中,它说: clear: Removes all elements from the list container (which are
在string :: clear函数的描述中,它说:

clear: Erases the contents of the string,which becomes an empty string (with a length of 0 characters).

在list :: clear函数的描述中,它说:

clear: Removes all elements from the list container (which are destroyed),and leaving the container with a size of 0.

清除是否覆盖字符串和列表的内存或只是释放它们?

解决方法

内存不会被覆盖.它甚至不能保证被释放.

例如,如果您创建一个巨大的字符串并调用其清除,则只会减小其大小,但仍可以保留分配的内存.但是,如果字符串超出范围,它将被释放.

std :: list至少保证列表中的元素将被清除,如果你清除列表.

所以,如果你的内存包含敏感数据,你应该手动覆盖它们.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读