由买买提看人间百态

topics

全部话题 - 话题: 析构
首页 上页 1 2 3 4 5 6 7 8 9 下页 末页 (共9页)
A**u
发帖数: 2458
1
来自主题: Programming版 - vector的析构问题
你这code写的太复杂了
看晕了哎
t****t
发帖数: 6806
2
来自主题: Programming版 - vector的析构问题
A::~A() { for (auto i: children) delete i; }
b***i
发帖数: 3043
3
来自主题: Programming版 - vector的析构问题
children->parent=a 是什么意思?
l********a
发帖数: 1154
4
来自主题: Programming版 - vector的析构问题

就是如果构造函数传入第一个参数是当前构造对象的父指针
A::A(A* a,int)
{
this->parent = a;
...
}
l********a
发帖数: 1154
5
来自主题: Programming版 - vector的析构问题

auto会报错,
我写成类似这样的,还是会出错
for (int i=0;i<(int)(this->children_.size());++i)
{
A *temp = this->children_[i];
delete temp;
}
b***i
发帖数: 3043
6
来自主题: Programming版 - vector的析构问题
but Children is not A, it's vector
l********a
发帖数: 1154
7
来自主题: Programming版 - vector的析构问题

children在this中是一个vector
有参构造函数中是.push_back(new A(this,n))这种形式添加到this->children的
每一个child都是A *保存在这个vector中,
就看做是html的tag吧,


<br /> </head><br /> <body>...</body><br /> </html><br /> 那html这个tag的parent=0,children.size()==2<br /> html.children[0] = &head (由于是递归初始化,添加的时候能得到head的地址)<br /> html.children[1] = &body<br /> head这个tag的parent = &html,children.size()==1<br /> head.children[0] = title<br /> title和body的children.size()==0,是个空vector<br /> parent分别是 &head 和 &html</span></div></td></tr></table></td> </tr> <tr> <td><table style="margin-top:0"><tr><td class="zt-author">t****t<br />发帖数: 6806</td><td width=80% class="zt-bg"><div id="post8" style="position:relative"><div class="zt-counter">8</div><div style="margin-bottom:20px;font-size:1.1em"><span style="font-weight:bold">来自主题: </span><span class="board">Programming版</span> - <a href="/zhuti/Programming/31220863/#post10" style="font-size:1.1em">vector<T *>的析构问题</a></div><span>this is c++11, but you got the essence. in any case, you have other bug in<br /> your code.</span></div></td></tr></table></td> </tr> <tr> <td><table style="margin-top:0"><tr><td class="zt-author">l********a<br />发帖数: 1154</td><td width=80% class="zt-bg2"><div id="post9" style="position:relative"><div class="zt-counter">9</div><div style="margin-bottom:20px;font-size:1.1em"><span style="font-weight:bold">来自主题: </span><span class="board">Programming版</span> - <a href="/zhuti/Programming/31220863/#post11" style="font-size:1.1em">vector<T *>的析构问题</a></div><span><br /> 多谢,继续调试中.</span></div></td></tr></table></td> </tr> <tr> <td><table style="margin-top:0"><tr><td class="zt-author">j*****g<br />发帖数: 16</td><td width=80% class="zt-bg"><div id="post10" style="position:relative"><div class="zt-counter">10</div><div style="margin-bottom:20px;font-size:1.1em"><span style="font-weight:bold">来自主题: </span><span class="board">Programming版</span> - <a href="/zhuti/Programming/31220863/#post12" style="font-size:1.1em">vector<T *>的析构问题</a></div><span>摸黑写了一下,可是编译(g++ A.cpp)出错, 就是this->children->parent<br /> A.cpp:20: error: base operand of ‘->’ has non-pointer type ‘std::vector<A<br /> *, std::allocator<A*> >’<br /> A.cpp<br /> //******************************<br /> 1 #include <vector><br /> 2 class A<br /> 3 {<br /> 4 public:<br /> 5 int num;<br /> 6 A *parent;<br /> 7 std::vector<A *> children;<br /> 8 public:<br /> 9 A(){<br /> 10 this->num=3;<br /> 11 this->parent=0;<br /> 12 for (int i=0;i<this->num;++i)<br /> 13 {<br /> 14 this->children.push_back(new A(this,this->num));<br /> 15 }<br /> 16 }<br /> 17 A(A *... <a href="/zhuti/Programming/31220863/#post12">阅读全帖</a></span></div></td></tr></table></td> </tr> <tr> <td><table style="margin-top:0"><tr><td class="zt-author">t****t<br />发帖数: 6806</td><td width=80% class="zt-bg2"><div id="post11" style="position:relative"><div class="zt-counter">11</div><div style="margin-bottom:20px;font-size:1.1em"><span style="font-weight:bold">来自主题: </span><span class="board">Programming版</span> - <a href="/zhuti/Programming/31220863/#post13" style="font-size:1.1em">vector<T *>的析构问题</a></div><span>你这写的什么破烂?<br /> <br /> <A</span></div></td></tr></table></td> </tr> <tr> <td><table style="margin-top:0"><tr><td class="zt-author">j*****g<br />发帖数: 16</td><td width=80% class="zt-bg"><div id="post12" style="position:relative"><div class="zt-counter">12</div><div style="margin-bottom:20px;font-size:1.1em"><span style="font-weight:bold">来自主题: </span><span class="board">Programming版</span> - <a href="/zhuti/Programming/31220863/#post14" style="font-size:1.1em">vector<T *>的析构问题</a></div><span>简单测试一下楼主的class, 发现这句不能compile:<br /> this->children->parent = a;<br /> main.cpp: In constructor ‘A::A(A*, int)’:<br /> main.cpp:25:<br /> error: base operand of ‘->’ has non-pointer type ‘std::vector<A*, std::<br /> allocator<A*> >’<br /> 这是为什么呢?多谢!</span></div></td></tr></table></td> </tr> <tr> <td><table style="margin-top:0"><tr><td class="zt-author">t****t<br />发帖数: 6806</td><td width=80% class="zt-bg2"><div id="post13" style="position:relative"><div class="zt-counter">13</div><div style="margin-bottom:20px;font-size:1.1em"><span style="font-weight:bold">来自主题: </span><span class="board">Programming版</span> - <a href="/zhuti/Programming/31220863/#post15" style="font-size:1.1em">vector<T *>的析构问题</a></div><span>他显然只是东拼西凑了一小段给你看一下, 你只能看个意思, copy paste是不成的</span></div></td></tr></table></td> </tr> <tr> <td><table style="margin-top:0"><tr><td class="zt-author">d***q<br />发帖数: 1119</td><td width=80% class="zt-bg"><div id="post14" style="position:relative"><div class="zt-counter">14</div><div style="margin-bottom:20px;font-size:1.1em"><span style="font-weight:bold">来自主题: </span><span class="board">Programming版</span> - <a href="/zhuti/Programming/31220863/#post16" style="font-size:1.1em">vector<T *>的析构问题</a></div><span>use<br /> shared_ptr</span></div></td></tr></table></td> </tr> <tr> <td><table style="margin-top:0"><tr><td class="zt-author">t****t<br />发帖数: 6806</td><td width=80% class="zt-bg2"><div id="post15" style="position:relative"><div class="zt-counter">15</div><div style="margin-bottom:20px;font-size:1.1em"><span style="font-weight:bold">来自主题: </span><span class="board">Programming版</span> - <a href="/zhuti/Programming/31220863/#post17" style="font-size:1.1em">vector<T *>的析构问题</a></div><span>你不用来来回回重复说明你的设计, 这个设计很简单, 大家都看明白了<br /> 大家问的是你混乱的语法问题, 你either没贴对or没贴全</span></div></td></tr></table></td> </tr> <tr> <td><table style="margin-top:0"><tr><td class="zt-author">l********a<br />发帖数: 1154</td><td width=80% class="zt-bg"><div id="post16" style="position:relative"><div class="zt-counter">16</div><div style="margin-bottom:20px;font-size:1.1em"><span style="font-weight:bold">来自主题: </span><span class="board">Programming版</span> - <a href="/zhuti/Programming/31220863/#post18" style="font-size:1.1em">vector<T *>的析构问题</a></div><span>不好意思,原class是个非常大的类,为了说问题简单,<br /> 我手打的时候,把带参数的构造函数那句写错了,应该是<br /> this->parent = a;<br /> 不是this->children->parent = a;<br /> 下面的测试用例复制可以编译运行的<br /> #include <string><br /> #include <vector><br /> using namespace std;<br /> #include <iostream><br /> class A<br /> {<br /> public:<br /> int num;<br /> A *parent;<br /> vector<A *> children;<br /> // 无参数调用<br /> A(void)<br /> {<br /> this->num = 3;<br /> this->parent = 0;<br /> for (int i=0;i<this->num;++i)<br /> this->children.push_back(new A(this,this->num-1));<br /> }<br /> // 子构造函数,被上面的无参函数调用<br /> A(A *a,int n)<br /> ... <a href="/zhuti/Programming/31220863/#post18">阅读全帖</a></span></div></td></tr></table></td> </tr> <tr> <td><table style="margin-top:0"><tr><td class="zt-author">b***i<br />发帖数: 3043</td><td width=80% class="zt-bg2"><div id="post17" style="position:relative"><div class="zt-counter">17</div><div style="margin-bottom:20px;font-size:1.1em"><span style="font-weight:bold">来自主题: </span><span class="board">Programming版</span> - <a href="/zhuti/Programming/31220863/#post19" style="font-size:1.1em">vector<T *>的析构问题</a></div><span>这就对了,你写好一个snippet,然后我们放到codepad.org上运行,就可以继续讨论了<br /> 另外,你那个A::~A里面的swap是谁跟谁?什么目的?</span></div></td></tr></table></td> </tr> <tr> <td><table style="margin-top:0"><tr><td class="zt-author">t****t<br />发帖数: 6806</td><td width=80% class="zt-bg"><div id="post18" style="position:relative"><div class="zt-counter">18</div><div style="margin-bottom:20px;font-size:1.1em"><span style="font-weight:bold">来自主题: </span><span class="board">Programming版</span> - <a href="/zhuti/Programming/31220863/#post20" style="font-size:1.1em">vector<T *>的析构问题</a></div><span>that is most probably copied from effective STL or some other book to "<br /> really" release the vector memory. but it's actually not needed.</span></div></td></tr></table></td> </tr> <tr> <td><table style="margin-top:0"><tr><td class="zt-author">t****t<br />发帖数: 6806</td><td width=80% class="zt-bg2"><div id="post19" style="position:relative"><div class="zt-counter">19</div><div style="margin-bottom:20px;font-size:1.1em"><span style="font-weight:bold">来自主题: </span><span class="board">Programming版</span> - <a href="/zhuti/Programming/31220863/#post22" style="font-size:1.1em">vector<T *>的析构问题</a></div><span>you read it wrong -- it said when you clear() the vector, or pop_back(), or<br /> erase(), it probably won't release the memory.<br /> but when you delete the vector, it will and it must.<br /> read book carefully.</span></div></td></tr></table></td> </tr> <tr> <td><table style="margin-top:0"><tr><td class="zt-author">b***i<br />发帖数: 3043</td><td width=80% class="zt-bg"><div id="post20" style="position:relative"><div class="zt-counter">20</div><div style="margin-bottom:20px;font-size:1.1em"><span style="font-weight:bold">来自主题: </span><span class="board">Programming版</span> - <a href="/zhuti/Programming/31220863/#post23" style="font-size:1.1em">vector<T *>的析构问题</a></div><span>那你就作出一个能出错的snippet,放到codepad上出错,再贴出来代码,好吗?<br /> 另外,你怎么不用delete,而是直接~?</span></div></td></tr></table></td> </tr> <tr> <td><table style="margin-top:0"><tr><td class="zt-author">t****t<br />发帖数: 6806</td><td width=80% class="zt-bg2"><div id="post21" style="position:relative"><div class="zt-counter">21</div><div style="margin-bottom:20px;font-size:1.1em"><span style="font-weight:bold">来自主题: </span><span class="board">Programming版</span> - <a href="/zhuti/Programming/31220863/#post25" style="font-size:1.1em">vector<T *>的析构问题</a></div><span>what is line 47 ?</span></div></td></tr></table></td> </tr> <tr> <td><table style="margin-top:0"><tr><td class="zt-author">b***i<br />发帖数: 3043</td><td width=80% class="zt-bg"><div id="post22" style="position:relative"><div class="zt-counter">22</div><div style="margin-bottom:20px;font-size:1.1em"><span style="font-weight:bold">来自主题: </span><span class="board">Programming版</span> - <a href="/zhuti/Programming/31220863/#post26" style="font-size:1.1em">vector<T *>的析构问题</a></div><span>把显式调用~A去掉。<br /> should I call destructor explicitly?<br /> <a href="http://www.parashift.com/c++-faq-lite/dtors.html#faq-11.5" rel="nofollow">http://www.parashift.com/c++-faq-lite/dtors.html#faq-11.5</a></span></div></td></tr></table></td> </tr> <tr> <td><table style="margin-top:0"><tr><td class="zt-author">l********a<br />发帖数: 1154</td><td width=80% class="zt-bg2"><div id="post23" style="position:relative"><div class="zt-counter">23</div><div style="margin-bottom:20px;font-size:1.1em"><span style="font-weight:bold">来自主题: </span><span class="board">Programming版</span> - <a href="/zhuti/Programming/31220863/#post27" style="font-size:1.1em">vector<T *>的析构问题</a></div><span>多谢2位,可能我代码哪里显式调用deconstructor了</span></div></td></tr></table></td> </tr> <tr> <td><table style="margin-top:0"><tr><td class="zt-author">t****t<br />发帖数: 6806</td><td width=80% class="zt-bg"><div id="post24" style="position:relative"><div class="zt-counter">24</div><div style="margin-bottom:20px;font-size:1.1em"><span style="font-weight:bold">来自主题: </span><span class="board">Programming版</span> - <a href="/zhuti/Programming/31220863/#post28" style="font-size:1.1em">vector<T *>的析构问题</a></div><span>...跟你说话真够费劲儿的. 都已经给你指出行号了你还"可能".</span></div></td></tr></table></td> </tr> <tr> <td><table style="margin-top:0"><tr><td class="zt-author">p***o<br />发帖数: 1252</td><td width=80% class="zt-bg2"><div id="post25" style="position:relative"><div class="zt-counter">25</div><div style="margin-bottom:20px;font-size:1.1em"><span style="font-weight:bold">来自主题: </span><span class="board">Programming版</span> - <a href="/zhuti/Programming/31221135/#post2" style="font-size:1.1em">map析构</a></div><span><br /> dll<br /> 出错原因是第二个有人说:insert在dll外分配内存, clear在dll内释放。<br /> 解决方法是第一个有人说:不能垮dll传递stl对象。<br /> 这跟是不是new出来的毫无关系,因为stl对象内部需要分配/释放内存。</span></div></td></tr></table></td> </tr> <tr> <td><table style="margin-top:0"><tr><td class="zt-author">b***i<br />发帖数: 3043</td><td width=80% class="zt-bg"><div id="post26" style="position:relative"><div class="zt-counter">26</div><div style="margin-bottom:20px;font-size:1.1em"><span style="font-weight:bold">来自主题: </span><span class="board">Programming版</span> - <a href="/zhuti/Programming/31221135/#post3" style="font-size:1.1em">map析构</a></div><span>什么是 ~pair?<br /> 写个snippeT</span></div></td></tr></table></td> </tr> <tr> <td><table style="margin-top:0"><tr><td class="zt-author">b***i<br />发帖数: 3043</td><td width=80% class="zt-bg2"><div id="post27" style="position:relative"><div class="zt-counter">27</div><div style="margin-bottom:20px;font-size:1.1em"><span style="font-weight:bold">来自主题: </span><span class="board">Programming版</span> - <a href="/zhuti/Programming/31221135/#post6" style="font-size:1.1em">map析构</a></div><span>if you use map ..... * param=new ...., then you use delete param in<br /> destructor of testGA. if you use auto, then no need to write anything. The<br /> destructor of map will be called.<br /> Show us more code before you make a snippet: including:<br /> testGA yourvariable, what did you do to this variable<br /> anythign done with params inside testGA,<br /> where did you do insert, where is node<br /> what did you do in destructor of testGA.<br /> <br /> make</span></div></td></tr></table></td> </tr> <tr> <td><table style="margin-top:0"><tr><td class="zt-author">p***o<br />发帖数: 1252</td><td width=80% class="zt-bg"><div id="post28" style="position:relative"><div class="zt-counter">28</div><div style="margin-bottom:20px;font-size:1.1em"><span style="font-weight:bold">来自主题: </span><span class="board">Programming版</span> - <a href="/zhuti/Programming/31221135/#post7" style="font-size:1.1em">map析构</a></div><span>This is a well-known problem for C++/dll and there are many solutions.<br /> Here are some.<br /> 1 Use dynamic linking for C/C++ library, e.g. msvcrt.dll, instead of<br /> static linking. You don't need to change your code but it probably<br /> won't work across compilers (even different versions).<br /> 2 Use C interface across binary modules and keep new/delete malloc/free<br /> in the same binary module. An additional benefit is it can also be<br /> used for other languages.<br /> 3 Use an allocator that can work across binary mod... <a href="/zhuti/Programming/31221135/#post7">阅读全帖</a></span></div></td></tr></table></td> </tr> <tr> <td><table style="margin-top:0"><tr><td class="zt-author">t****t<br />发帖数: 6806</td><td width=80% class="zt-bg2"><div id="post29" style="position:relative"><div class="zt-counter">29</div><div style="margin-bottom:20px;font-size:1.1em"><span style="font-weight:bold">来自主题: </span><span class="board">Programming版</span> - <a href="/zhuti/Programming/31221135/#post8" style="font-size:1.1em">map析构</a></div><span>我以为dll都是dynamic linking的呢, 我真是out了呀.<br /> 好象unix上.so没这问题...</span></div></td></tr></table></td> </tr> <tr> <td><table style="margin-top:0"><tr><td class="zt-author">l********a<br />发帖数: 1154</td><td width=80% class="zt-bg"><div id="post30" style="position:relative"><div class="zt-counter">30</div><div style="margin-bottom:20px;font-size:1.1em"><span style="font-weight:bold">来自主题: </span><span class="board">Programming版</span> - <a href="/zhuti/Programming/31221135/#post9" style="font-size:1.1em">map析构</a></div><span><br /> thank you so much for your comments. I am sure that you pointed the key<br /> problem of working around with stl variables crossing dlls. I 've found<br /> those solutions you mentioned above on internet.<br /> Unfortunately, I am the only one to take care of such an outdated c library<br /> and port it into c++. I am not sure if the first one (using dynamic linking<br /> for c/c++ library) could solve my problem easily (I doubt it). The last<br /> solution to use an allocator is quite difficult for me at this moment. So,<br /> the bes... <a href="/zhuti/Programming/31221135/#post9">阅读全帖</a></span></div></td></tr></table></td> </tr> <tr> <td><table style="margin-top:0"><tr><td class="zt-author">p***o<br />发帖数: 1252</td><td width=80% class="zt-bg2"><div id="post31" style="position:relative"><div class="zt-counter">31</div><div style="margin-bottom:20px;font-size:1.1em"><span style="font-weight:bold">来自主题: </span><span class="board">Programming版</span> - <a href="/zhuti/Programming/31221135/#post10" style="font-size:1.1em">map析构</a></div><span>VC里一直都是这样啊,再加上Debug/Release和Single/Multi-Threaded(现在没Single<br /> 了),<br /> 发布一个DLL可以有七八个binary ...</span></div></td></tr></table></td> </tr> <tr> <td><table style="margin-top:0"><tr><td class="zt-author">p***o<br />发帖数: 1252</td><td width=80% class="zt-bg"><div id="post32" style="position:relative"><div class="zt-counter">32</div><div style="margin-bottom:20px;font-size:1.1em"><span style="font-weight:bold">来自主题: </span><span class="board">Programming版</span> - <a href="/zhuti/Programming/31221135/#post12" style="font-size:1.1em">map析构</a></div><span>I would say the library could be outdated, but you can still use<br /> its inferface. That probably will save you a lot of trouble.<br /> <br /> library<br /> linking</span></div></td></tr></table></td> </tr> <tr> <td><table style="margin-top:0"><tr><td class="zt-author">p*a<br />发帖数: 592</td><td width=80% class="zt-bg2"><div id="post33" style="position:relative"><div class="zt-counter">33</div><div style="margin-bottom:20px;font-size:1.1em"><span style="font-weight:bold">来自主题: </span><span class="board">Programming版</span> - <a href="/zhuti/Programming/31221135/#post14" style="font-size:1.1em">map析构</a></div><span>编译选项用的/MT还是/MD?</span></div></td></tr></table></td> </tr> <tr> <td><table style="margin-top:0"><tr><td class="zt-author">l********a<br />发帖数: 1154</td><td width=80% class="zt-bg"><div id="post34" style="position:relative"><div class="zt-counter">34</div><div style="margin-bottom:20px;font-size:1.1em"><span style="font-weight:bold">来自主题: </span><span class="board">Programming版</span> - <a href="/zhuti/Programming/31221135/#post15" style="font-size:1.1em">map析构</a></div><span><br /> /MDd,多线程调试dll</span></div></td></tr></table></td> </tr> <tr> <td><table style="margin-top:0"><tr><td class="zt-author">l********a<br />发帖数: 1154</td><td width=80% class="zt-bg2"><div id="post35" style="position:relative"><div class="zt-counter">35</div><div style="margin-bottom:20px;font-size:1.1em"><span style="font-weight:bold">来自主题: </span><span class="board">Programming版</span> - <a href="/zhuti/Programming/31221135/#post16" style="font-size:1.1em">map析构</a></div><span><br /> 今天准备一个函数一个函数的注释掉试验了.<br /> 我也觉得我不存在跨dll使用stl的问题,因为所有的自定义类都在同一个dll内部<br /> 或许是文件读写和内存分配的时候出的问题.<br /> 多谢几位,有问题再来请教</span></div></td></tr></table></td> </tr> <tr> <td><table style="margin-top:0"><tr><td class="zt-author">b***i<br />发帖数: 3043</td><td width=80% class="zt-bg"><div id="post36" style="position:relative"><div class="zt-counter">36</div><div style="margin-bottom:20px;font-size:1.1em"><span style="font-weight:bold">来自主题: </span><span class="board">Programming版</span> - <a href="/zhuti/Programming/31221135/#post17" style="font-size:1.1em">map析构</a></div><span>主程序和dll的选项要一致</span></div></td></tr></table></td> </tr> <tr> <td><table style="margin-top:0"><tr><td class="zt-author">l********a<br />发帖数: 1154</td><td width=80% class="zt-bg2"><div id="post37" style="position:relative"><div class="zt-counter">37</div><div style="margin-bottom:20px;font-size:1.1em"><span style="font-weight:bold">来自主题: </span><span class="board">Programming版</span> - <a href="/zhuti/Programming/31221135/#post18" style="font-size:1.1em">map析构</a></div><span><br /> 这里的测试程序是我写的<br /> 实际项目中,那个exe是一个很大的程序,我也不确定它是用什么选项编译的<br /> 我这里只能试验了吧</span></div></td></tr></table></td> </tr> <tr> <td><table style="margin-top:0"><tr><td class="zt-author">b***i<br />发帖数: 3043</td><td width=80% class="zt-bg"><div id="post38" style="position:relative"><div class="zt-counter">38</div><div style="margin-bottom:20px;font-size:1.1em"><span style="font-weight:bold">来自主题: </span><span class="board">Programming版</span> - <a href="/zhuti/Programming/31221135/#post19" style="font-size:1.1em">map析构</a></div><span>不是你一起编译的?<br /> 你用什么编译器?那个是什么编译器?</span></div></td></tr></table></td> </tr> <tr> <td><table style="margin-top:0"><tr><td class="zt-author">l********a<br />发帖数: 1154</td><td width=80% class="zt-bg2"><div id="post39" style="position:relative"><div class="zt-counter">39</div><div style="margin-bottom:20px;font-size:1.1em"><span style="font-weight:bold">来自主题: </span><span class="board">Programming版</span> - <a href="/zhuti/Programming/31221135/#post20" style="font-size:1.1em">map析构</a></div><span><br /> 是cad软件二次开发,他们怎么编译的我还真不知道,我只负责写个dll供它程序调用<br /> 功能执行良好,然后弹出一个heap错误后就程序退出了<br /> 应该是哪部分内存分配的问题,c++断续用过,第一次上一个完整的大项目,出了问题到处<br /> 试验.<br /> 我是vs2008,那个软件不清楚怎么编译的</span></div></td></tr></table></td> </tr> <tr> <td><table style="margin-top:0"><tr><td class="zt-author">b***i<br />发帖数: 3043</td><td width=80% class="zt-bg"><div id="post40" style="position:relative"><div class="zt-counter">40</div><div style="margin-bottom:20px;font-size:1.1em"><span style="font-weight:bold">来自主题: </span><span class="board">Programming版</span> - <a href="/zhuti/Programming/31221135/#post21" style="font-size:1.1em">map析构</a></div><span>如果你认为你自己的代码没有问题,不妨加入一些调试信息,看看主程序生成testGA的<br /> 实例和释放的时候有没有问题。<br /> <br /> dll</span></div></td></tr></table></td> </tr> <tr> <td><table style="margin-top:0"><tr><td class="zt-author">c**y<br />发帖数: 172</td><td width=80% class="zt-bg2"><div id="post41" style="position:relative"><div class="zt-counter">41</div><div style="margin-bottom:20px;font-size:1.1em"><span style="font-weight:bold">来自主题: </span><span class="board">Programming版</span> - <a href="/zhuti/Programming/31223311/#post6" style="font-size:1.1em">弱弱的问个关于C++的问题:如何创建一个存放常数数组的文件,</a></div><span>同意<br /> card.h 里只定义这个类<br /> card.cpp 里定义它的析构和解析函数用来初始化和释放动态内存</span></div></td></tr></table></td> </tr> <tr> <td><table style="margin-top:0"><tr><td class="zt-author">b*******s<br />发帖数: 5216</td><td width=80% class="zt-bg"><div id="post42" style="position:relative"><div class="zt-counter">42</div><div style="margin-bottom:20px;font-size:1.1em"><span style="font-weight:bold">来自主题: </span><span class="board">Programming版</span> - <a href="/zhuti/Programming/31228515/#post3" style="font-size:1.1em">一个Quant Developer的C++面试题</a></div><span>就在析构器里面调用callback的指针咯</span></div></td></tr></table></td> </tr> <tr> <td><table style="margin-top:0"><tr><td class="zt-author">b*******s<br />发帖数: 5216</td><td width=80% class="zt-bg2"><div id="post43" style="position:relative"><div class="zt-counter">43</div><div style="margin-bottom:20px;font-size:1.1em"><span style="font-weight:bold">来自主题: </span><span class="board">Programming版</span> - <a href="/zhuti/Programming/31228515/#post6" style="font-size:1.1em">一个Quant Developer的C++面试题</a></div><span>不用传对象指针,一个函数指针就可以了<br /> 另外使用前先检查指针有效性,否则在析构器里面扔出异常要被骂的</span></div></td></tr></table></td> </tr> <tr> <td><table style="margin-top:0"><tr><td class="zt-author">c*****e<br />发帖数: 3226</td><td width=80% class="zt-bg"><div id="post44" style="position:relative"><div class="zt-counter">44</div><div style="margin-bottom:20px;font-size:1.1em"><span style="font-weight:bold">来自主题: </span><span class="board">Programming版</span> - <a href="/zhuti/Programming/31251593/#post1" style="font-size:1.1em">转贴:[圣战] python 是个讨厌的语言</a></div><span>这篇帖子的目的虽然不是为了引发圣战, 但是鄙人已经遇 见到了, 故而添加这个标签,<br /> 告诉大家,参与讨论需要谨 慎, 切忌人身攻击, 切记切记!<br /> 我不是用黑Python 装逼的, 任何有此想法的人请绕道. 要 装逼有比黑Python 方便的<br /> 多的多的办法. 所以要黑Python而不是那些比Python还要烂的语言, 是 因为他们都是<br /> 小众语言, 还不足矣需要黑他们<br /> 但是Python 这个跳梁小丑越来越嚣张了, 必须揭示一下 其罪恶的一面, 以正视听.<br /> 欢迎大家正常的拍砖吐嘈. 这个说来比较久远了, 可能部 分人已经看过了:)<br /> 以下为正文, 摘自Q群的讲座. 原始链接 <a href="https://avlog.avplayer.org/3597082/" rel="nofollow">https://avlog.avplayer.org/3597082/</a><br /> python%E6%98%AF%E4%B8% AA%E7%83%82%E8%AF%AD%E8%A8%80.html<br /> PS: 好奇Q群聊天记录怎么来的? 聊天记录由该群一干人等开发的avbot (Q群云秘书<a href="http://qqbot.avplayer.org" rel="nofollow">http://qqbot.avplayer.org</a> ) 生成.<br /> --------------------------------------------... <a href="/zhuti/Programming/31251593/#post1">阅读全帖</a></span></div></td></tr></table></td> </tr> <tr> <td><table style="margin-top:0"><tr><td class="zt-author">y**b<br />发帖数: 10166</td><td width=80% class="zt-bg2"><div id="post45" style="position:relative"><div class="zt-counter">45</div><div style="margin-bottom:20px;font-size:1.1em"><span style="font-weight:bold">来自主题: </span><span class="board">Programming版</span> - <a href="/zhuti/Programming/31253411/#post9" style="font-size:1.1em">请问释放容器内存的方法</a></div><span>折腾了几天,感觉这个问题可能无解,也许C++标准就不认为这是个问题。<br /> 先后测试了四种allocator,没有一个能生效,这里也有人提到:<br /> <a href="http://bytes.com/topic/c/answers/133169-return-memory-os" rel="nofollow">http://bytes.com/topic/c/answers/133169-return-memory-os</a><br /> 1. new/delete:<br /> <a href="http://www.josuttis.com/cppcode/allocator.html" rel="nofollow">http://www.josuttis.com/cppcode/allocator.html</a><br /> 2. malloc/free (跟1类似):<br /> <a href="http://www.usidcbbs.com/read-htm-tid-4896-fpage-3.html" rel="nofollow">http://www.usidcbbs.com/read-htm-tid-4896-fpage-3.html</a><br /> 3. boost::pool_allocator, boost::fast_pool_allocator:<br /> <a href="http://www.boost.org/doc/libs/1_53_0/libs/pool/doc/html/boost_p" rel="nofollow">http://www.boost.org/doc/libs/1_53_0/libs/pool/doc/html/boost_p</a><br /> rfaces.html#boost_pool.pool.interfaces.interfaces.pool_allocator<br /> 无论release_memory, purge_memory都无实效,而且容易出现seg fault。... <a href="/zhuti/Programming/31253411/#post9">阅读全帖</a></span></div></td></tr></table></td> </tr> <tr> <td><table style="margin-top:0"><tr><td class="zt-author">t****t<br />发帖数: 6806</td><td width=80% class="zt-bg"><div id="post46" style="position:relative"><div class="zt-counter">46</div><div style="margin-bottom:20px;font-size:1.1em"><span style="font-weight:bold">来自主题: </span><span class="board">Programming版</span> - <a href="/zhuti/Programming/31253411/#post11" style="font-size:1.1em">请问释放容器内存的方法</a></div><span>你这里混淆了两个概念(在你bytes.com的link里有人已经提到了): 堆内存的分配/释放<br /> , 即new/delete, 和进程内存的分配/释放, 即brk, 是两个不同的概念. 用ps/top看到<br /> 的是第二种, 但STL能控制的基本上是第一种.<br /> 先说STL的容器. clear当然不能保证释放, 但是析构函数一定会保证. 所以你如果不能<br /> 确定swap()能不能work, 不妨重新分配容器. 性能应该比swap高, 但是你反正是试一下<br /> , 不用太担心.<br /> 再说OS. 在linux上, 缺省的glibc的分配模式是, 对于小内存块, 针对不同的尺寸, 有<br /> 不同的内存池. 对于大内存块, 是用mmap直接从系统要的. 对于内存池的delete, 就还<br /> 给内存池了, OS仍然看不到. 对于mmap的delete, 直接还给OS. 从一方面, 这可以解释<br /> 为什么vector是能"完全"释放, 因为vector的内存一定是连续的, 你开一个大vector肯<br /> 定是用mmap直接拿的, 删除之后就没了. 对于unordered_set, 内存不连续, 是渐渐分配<br /> 的, 很多删除之后还给内存池了, 所... <a href="/zhuti/Programming/31253411/#post11">阅读全帖</a></span></div></td></tr></table></td> </tr> <tr> <td><table style="margin-top:0"><tr><td class="zt-author">N******K<br />发帖数: 10202</td><td width=80% class="zt-bg2"><div id="post47" style="position:relative"><div class="zt-counter">47</div><div style="margin-bottom:20px;font-size:1.1em"><span style="font-weight:bold">来自主题: </span><span class="board">Programming版</span> - <a href="/zhuti/Programming/31304709/#post32" style="font-size:1.1em">问个c++ struct和指针问题</a></div><span>我举个例子<br /> 矩阵加法 每个都是1024x0124大小<br /> A=B+C+D<br /> 具体这样 temp1=B+C; temp2=temp1+D; A=temp2;<br /> 这里面很多数据共享的问题 <br /> 比如 简单的 A=B;<br /> A是一个矩阵 A=B 是不是要把所有元素都复制一遍? 显然不用<br /> A.data=B.data; 就行了<br /> A.data 可以是 shared_part<arraytype><br /> 如果要对A只做读操作 A不用重新分配一块内存<br /> 如果要对A做写操作 那就测试一下A.data有没有别人在用 还有人用的话 那就复制一块<br /> A重新分配一块内存 复制A.data指向的数据<br /> 当然 你要搞多线程 多个线程写一个矩阵 会出问题 你要加锁<br /> 锁。lock()<br /> 测试一下A.data有没有别人在用 还有人用的话 A重新分配一块内存<br /> 锁。unlock()<br /> 不过 数值计算一般不会这么搞<br /> 如果B没用了 析构函数里面 {data.reset()} 就可以了 不会把数据真给删掉了</span></div></td></tr></table></td> </tr> <tr> <td><table style="margin-top:0"><tr><td class="zt-author">D***n<br />发帖数: 6804</td><td width=80% class="zt-bg"><div id="post48" style="position:relative"><div class="zt-counter">48</div><div style="margin-bottom:20px;font-size:1.1em"><span style="font-weight:bold">来自主题: </span><span class="board">Programming版</span> - <a href="/zhuti/Programming/31388973/#post1" style="font-size:1.1em">C++糟粕和需要避免的。</a></div><span>基本上我认为这些特性都是C++的糟粕:<br /> 1)模板:模板的本意是把type和control flow分开,多个type可以共享一个control<br /> flow。但是它引发的问题远比带来的方便程度要多。最后大多数模板都搞成一个杂种:<br /> 被塞入各种特化。<br /> 我的建议:STL一类成熟的可以用,但是能不用就不用。<br /> 2)基本操作符重载:当一个正常人看到A=B居然引发了另外一个线程SIGABT的时候,你<br /> 会想到这么一个赋值语句居然触发了某个析构函数把内存给清空了的事情吗?面对现实<br /> 吧,这个东西引起的麻烦远远超过其便利性。<br /> 至少至少,重载的操作符应该和正常符号分开,比如 = 改成 |= 一类。<br /> 3)重载:重载是个好主意,问题在:1)库里面这些重载的函数会被替换成别的函数名<br /> 称用于链接,这个替换协议不仅不是标准的一部份,而且还巨复杂。2)只能重载基本<br /> 类型。基本上就是一个残废功能。<br /> 我的方法:与其让系统自动起名字,不如我自己给他起,比如 init_IntInt, init_Int<br /> , int<br /> 4)const<br /> 当我读到 Thinking in C++ ,作者开始介绍const的时候,我就开始讨厌C++了,因为<br /> c... <a href="/zhuti/Programming/31388973/#post1">阅读全帖</a></span></div></td></tr></table></td> </tr> <tr> <td><table style="margin-top:0"><tr><td class="zt-author">z****e<br />发帖数: 54598</td><td width=80% class="zt-bg2"><div id="post49" style="position:relative"><div class="zt-counter">49</div><div style="margin-bottom:20px;font-size:1.1em"><span style="font-weight:bold">来自主题: </span><span class="board">Programming版</span> - <a href="/zhuti/Programming/31418959/#post4" style="font-size:1.1em">go几天的一些感受</a></div><span>作为论据,我找到了中文的翻译,但是那个youtub链接失效了<br /> Go语言之父谈Go:大道至简<br /> 时间:2012-07-05 15:40 作者:王然<br /> 导读:这篇文章是Google首席工程师、Go语言之父Rob Pike自己整理的6月21日在旧金<br /> 山给Go SF的演讲稿。Rob提到:Go语言本是以C为原型,以C++为目标设计,但最终却大<br /> 相径庭。值得一提的是,这3门语言都曾当选TIOBE年度语言。<br /> 几个礼拜之前我被问到:“对于Go语言,最令你惊讶的是什么?”当时我就明确地给出<br /> 了答案:“虽然我希望C++程序员能够使用Go作为替代拼,但实际上大部分Go程序员都<br /> 是从Python和Ruby转过来的,其中却少有C++程序员。”<br /> 我、Ken以及Robert都曾是C++程序员,在我们编写软件时觉得应该设计一门更适合解决<br /> 这个问题的编程语言。奇怪的是,其他程序员似乎却不关心。<br /> 今天我将说说是什么让我们决定创造Go语言的,及其出乎意料的结果。这里我谈的更多<br /> 的会是Go而不是C++,所以即使你不懂C++也没关系。<br /> 主旨可以简单地总结为:你更同意Less is more还是Less is less?<br /> 这里有一个... <a href="/zhuti/Programming/31418959/#post4">阅读全帖</a></span></div></td></tr></table></td> </tr> <tr> <td><table style="margin-top:0"><tr><td class="zt-author">b***i<br />发帖数: 3043</td><td width=80% class="zt-bg"><div id="post50" style="position:relative"><div class="zt-counter">50</div><div style="margin-bottom:20px;font-size:1.1em"><span style="font-weight:bold">来自主题: </span><span class="board">Programming版</span> - <a href="/zhuti/Programming/31449081/#post4" style="font-size:1.1em">服务器端纯的asio的异步怎么写?</a></div><span>另外,我是把io_service.run()放在线程A里的,而run()在等待的时候确实能够进行服<br /> 务器的服务,但是,当我需要结束的时候不知道如何通知这个线程A停止。结果Windows<br /> 下出现对话框,Abort, Retry, ...<br /> 应该是这个thread A析构的时候出了错。</span></div></td></tr></table></td> </tr> </tbody></table></div> </div> <div id="pager" style="margin-top:25px"> <div><table class="searchpages" style="float: right"><tbody><tr> <td><a href="/huati/析构/">首页</a></td> <td><a href="/huati/析构/3">上页</a></td> <td><a href="/huati/析构/">1</a></td> <td><a href="/huati/析构/2">2</a></td> <td><a href="/huati/析构/3">3</a></td> <td>4</td> <td><a href="/huati/析构/5">5</a></td> <td><a href="/huati/析构/6">6</a></td> <td><a href="/huati/析构/7">7</a></td> <td><a href="/huati/析构/8">8</a></td> <td><a href="/huati/析构/9">9</a></td> <td><a href="/huati/析构/5">下页</a></td> <td><a href="/huati/析构/9">末页</a></td> <td>(共9页)</td> </tr> </tbody></table></div> </div> </div> <span class="anchor" id="line-3"></span><span class="anchor" id="bottom"></span></div><div id="pagebottom"></div></div><div class="sidebar"><div dir="ltr" id="SideBar.sidebar" lang="zh"><span class="anchor" id="SideBar.top"></span> <span class="anchor" id="SideBar.line-1"></span><span class="anchor" id="SideBar.line-2"></span><p class="line867"><div id="rankings"><h3>未名新帖统计<span>// 7月16日</span></h3><div><table width=100%><tr><th width=10% align=left>#</th><th width=50% align=left>版面</th><th width=40% align=left>帖数(主题数)</th></tr><tr><td>-</td><td>全站</td><td>4871 (796)</td></tr><tr><td>1</td><td><a title="军事天地" href="/board/Military/">Military</a></td><td>3777 (569)</td></tr><tr><td>2</td><td><a title="股海弄潮" href="/board/Stock/">Stock</a></td><td>341 (51)</td></tr><tr><td>3</td><td><a title="肚皮舞运动" href="/board/Joke/">Joke</a></td><td>117 (17)</td></tr><tr><td>4</td><td><a title="史海钩沉" href="/board/History/">History</a></td><td>116 (3)</td></tr><tr><td>5</td><td><a title="车轮上的传奇" href="/board/Automobile/">Automobile</a></td><td>100 (9)</td></tr><tr><td>6</td><td><a title="美国新闻" href="/board/USANews/">USANews</a></td><td>55 (9)</td></tr><tr><td>7</td><td><a title="人到中年" href="/board/Midlife/">Midlife</a></td><td>45 (1)</td></tr><tr><td>8</td><td><a title="焦点新闻" href="/board/Headline/">Headline</a></td><td>41 (41)</td></tr><tr><td>9</td><td><a title="梦里花落知多少" href="/board/Dreamer/">Dreamer</a></td><td>33 (13)</td></tr><tr><td>10</td><td><a title="二手市场" href="/board/FleaMarket/">FleaMarket</a></td><td>32 (20)</td></tr><tr><td>11</td><td><a title="家居生活" href="/board/Living/">Living</a></td><td>30 (7)</td></tr></table><p>* 这里只显示发帖超过25的版面,努力灌水吧:-)</p></div></div> <span class="anchor" id="SideBar.line-3"></span><div id="matched_content" style="margin: 5px 2px 5px 2px"></div> <span class="anchor" id="SideBar.line-4"></span> <h3 id="SideBar.A.2BU4ZT8k4KdoROylkp-">历史上的今天</h3> <span class="anchor" id="SideBar.line-5"></span><p class="line867"><div class="BlikiSummary" style="margin-bottom:1.2em;margin-left:0.5em"><ol><li><a href="/zhuti/ChineseClassics/31268413/">faintcat妹妹看进来~~</a> 发表于12年前.</li><li><a href="/zhuti/EB23/31380293/">NSC, PD 1/7/2007, EB2, ...</a> 发表于11年前.</li><li><a href="/zhuti/FleaMarket/35696181/">[FBA求购]MJVE2 758 MJVM2 ...</a> 发表于6年前.</li><li><a href="/zhuti/Parenting/31948559/">老生常谈,归与不归</a> 发表于10年前.</li><li><a href="/zhuti/board/31486231/">【申请】Seattle西雅图 版版主——申请人...</a> 发表于9年前.</li><li><a href="/zhuti/NextGeneration/36332471/">宝宝出生,头骨骨折,求祝福</a> 发表于9年前.</li><li><a href="/zhuti/ClassicalMusic/31210935/">求推荐舒缓优美的古典音乐</a> 发表于11年前.</li><li><a href="/zhuti/PhotoGear/34338217/">百分之一的北京人上北大 中国网友愤怒(转载)</a> 发表于10年前.</li><li><a href="/zhuti/pets/31825797/">新人带狗狗Bailey来报道</a> 发表于12年前.</li><li><a href="/zhuti/Football/31468183/">全世界最有价值的运动队</a> 发表于10年前.</li><li><a href="/zhuti/Automobile/35426999/">请问大切诺基的质量如何</a> 发表于6年前.</li><li><a href="/zhuti/_RuS/23459405/">TNND,军版全是BKC</a> 发表于15年前.</li><li><a href="/zhuti/_LoTaYu/31206385/">Inception</a> 发表于12年前.</li><li><a href="/zhuti/Seattle/32526849/">微软的有些家属可真恶心,为了卖保险脸都不要了</a> 发表于10年前.</li><li><a href="/zhuti/Military/39967953/">每周坐高铁的苦逼来说说感受吧!!</a> 发表于9年前.</li></ol></div> <span class="anchor" id="SideBar.line-6"></span> <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-2229050667028251" crossorigin="anonymous"></script> <!-- SidebarW1 --> <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-2229050667028251" data-ad-slot="2711874079" data-ad-format="auto" data-full-width-responsive="true"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> <span class="anchor" id="SideBar.line-7"></span><span class="anchor" id="SideBar.bottom"></span></div><div id="sidebar-end"></div></div></div><div class="footer"><span class="license">除非另有声明,本站内容采用Creative Commons BY-NC-SA 3.0协议进行许可,转载请注明来自<a href="/">未名观察</a> - <a href="/PrivacyPolicy">隐私政策</a></span><span class="time" lang="zh" dir="ltr">2017-12-02 11:50:45由<span title="admin"><a href="/admin" title="admin">admin</a></span>编辑</span> </div> <script> var _gaq=[['_setAccount','UA-18482428-3'],['_trackPageview'],['_trackPageLoadTime']]; (function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0]; g.src=('https:'==location.protocol?'//ssl':'//www')+'.google-analytics.com/ga.js'; s.parentNode.insertBefore(g,s)}(document,'script')); </script> <script type="text/javascript" src="http://s.skimresources.com/js/27394X857871.skimlinks.js"></script> </body> </html>