avatar
CF卡如何删除分区# PhotoGear - 摄影器材
g*j
1
当constructor里面的某个member在initialization的时候fail了,到底会有memory
leak么?其他的已经完成的member到底由谁来释放?是系统自己自动释放还是需要在
catch exception之后用户写代码来自己释放?
我曾经看过说“C++里面没有partially constructed object, 只有full constructed
object”,难道不是说没有memory leak么?
为什么在Effective C++里面有这样一句话“if an exception is thrown during
construction of an object, any parts of the object that have already been
fully constructed are automatically destroyed”,这是不是说,只要throw
exception就够了,不需要在catch之后在代码里面释放? 如果这样,是不是说哪怕
fail也没有memory leak了?
总之,这个地方很confuse,谁来解释一下?
avatar
p*e
2
通常的 管理 下的删除分区居然没法用
avatar
x*y
3
I have not used C++ for a long time, but I think I remeber this.
First of all, you can definitely having a try catch for constructor or
destructor
2nd of all, all the objects in the stack will be unwinded
3nd of all, the object on the heap will not.
avatar
t*8
4
computer management-->Disk management

【在 p********e 的大作中提到】
: 通常的 管理 下的删除分区居然没法用
avatar
s*0
5
If you throw during construction, you will get a leak (on whatever pointer
you allocated memory to).
You can avoid this by using smart pointers.
avatar
p*e
6
我就是说这个没法用

【在 t*******8 的大作中提到】
: computer management-->Disk management
avatar
d*x
7
in ctor, whatever, it is okay
in dtor, exception must be caught internally.

【在 x***y 的大作中提到】
: I have not used C++ for a long time, but I think I remeber this.
: First of all, you can definitely having a try catch for constructor or
: destructor
: 2nd of all, all the objects in the stack will be unwinded
: 3nd of all, the object on the heap will not.

avatar
t*8
8
那就试一下个第三方的分区软件
DiskDirectorSuite

【在 p********e 的大作中提到】
: 我就是说这个没法用
avatar
d*x
9
已经完成的member会回滚的,但是如果你是new出来的,你必须要手动delete才行。
另外c++的异常处理就是个渣,直接disable了得了。。

constructed

【在 g***j 的大作中提到】
: 当constructor里面的某个member在initialization的时候fail了,到底会有memory
: leak么?其他的已经完成的member到底由谁来释放?是系统自己自动释放还是需要在
: catch exception之后用户写代码来自己释放?
: 我曾经看过说“C++里面没有partially constructed object, 只有full constructed
: object”,难道不是说没有memory leak么?
: 为什么在Effective C++里面有这样一句话“if an exception is thrown during
: construction of an object, any parts of the object that have already been
: fully constructed are automatically destroyed”,这是不是说,只要throw
: exception就够了,不需要在catch之后在代码里面释放? 如果这样,是不是说哪怕
: fail也没有memory leak了?

avatar
g*w
10
如果class的成员都是纯正100% object,那么不用担心leak问题。没有指针,不要用
char* s = new char[100]; 不要用OS API, 而是包装过的类库。
avatar
s*0
11
Do you care about your application's footprint and performance?

【在 g**w 的大作中提到】
: 如果class的成员都是纯正100% object,那么不用担心leak问题。没有指针,不要用
: char* s = new char[100]; 不要用OS API, 而是包装过的类库。

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。