This is my real problem. I have need two big struct variables for each loop. So, my current code goes like following struct{ //some stl, like vector, map. } yesterday = null; today = get_data(1); for (i = 2; i != end; ++i){ yesterday = today; today = get_data(i); //some function handle yesterday and today. } So, what should I do to avoid memory leakage? Thanks.
【在 J*****n 的大作中提到】 : : This is my real problem. I have need two big struct variables for each loop. : So, my current code goes like following : struct{ : //some stl, like vector, map. : } : yesterday = null; : today = get_data(1); : for (i = 2; i != end; ++i){ : yesterday = today;
this is ok as long as you release yesterday and today after the loop. ignore that Paul guy, he often pretends he know c++, but actually he knows absolutely nothing about it.
loop.
【在 J*****n 的大作中提到】 : : This is my real problem. I have need two big struct variables for each loop. : So, my current code goes like following : struct{ : //some stl, like vector, map. : } : yesterday = null; : today = get_data(1); : for (i = 2; i != end; ++i){ : yesterday = today;
A*e
25 楼
你太牛了,我光看到了俩大腮帮子。。。。
【在 r****y 的大作中提到】 : 我看了半天,仿佛差点看出锁骨美。。。
S*z
26 楼
会,3个new一个delete?这样的好事哪里找? 请在return之前把另外两个delete补上
【在 J*****n 的大作中提到】 : struct D{ : vector p; : vector q; : } : D *a, *b; : int main(){ : a = new D; : b = new D; : delete b; : b = a;
M*u
27 楼
No
【在 J*****n 的大作中提到】 : struct D{ : vector p; : vector q; : } : D *a, *b; : int main(){ : a = new D; : b = new D; : delete b; : b = a;
what I concern is that if I delete a struct, which contains a stl container. When the delete is called, the container is always released or just like we call del on array, which will generate memory leakage (we need to call delete[])? Thank you.
【在 t****t 的大作中提到】 : this is ok as long as you release yesterday and today after the loop. : ignore that Paul guy, he often pretends he know c++, but actually he knows : absolutely nothing about it. : : loop.
t*t
31 楼
objects in struct are properly destroyed when struct is destroyed.
container. we
【在 J*****n 的大作中提到】 : what I concern is that if I delete a struct, which contains a stl container. : When the delete is called, the container is always released or just like we : call del on array, which will generate memory leakage (we need to call : delete[])? : Thank you.
X*r
32 楼
and delete yesterday before it is re-assigned. (assuming get_data returns a new struct every time)
knows
【在 t****t 的大作中提到】 : this is ok as long as you release yesterday and today after the loop. : ignore that Paul guy, he often pretends he know c++, but actually he knows : absolutely nothing about it. : : loop.
S*g
33 楼
这个是最基本的C++吧,C++ FAQ, C++ FAQ Lite, thinking in C++都有讲
【在 t****t 的大作中提到】 : objects in struct are properly destroyed when struct is destroyed. : : container. : we