由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - Will it coz memory leakage?
相关主题
c++ copy reference 还是deep copy尼玛,这也太容易赚钱了。
有一事我一直就是不明白在并发上haskell可以秒go吗
电话面试题一问 (转载)Google got it wrong. The open-office trend is destroying the workplace.
What is the side effect not to call sem_destroy()?请教一个windows下面的编程问题
请教一个系统设计问题问个C++的基础问题
问个 ctor/copy ctor的问题The staff is so ....
is pthread_mutex_destroy() required to call?弱问:singleton要不要destructor啊?
软件业里最著名的一句话my wet was deleted?
相关话题的讨论汇总
话题: struct话题: leakage话题: delete话题: vector话题: memory
进入Programming版参与讨论
1 (共1页)
J*****n
发帖数: 4859
1
struct D{
vector p;
vector q;
}
D *a, *b;
int main(){
a = new D;
b = new D;
delete b;
b = a;
a = new D;
return;
}
Thank you.
P********e
发帖数: 2610
2
yes.

【在 J*****n 的大作中提到】
: struct D{
: vector p;
: vector q;
: }
: D *a, *b;
: int main(){
: a = new D;
: b = new D;
: delete b;
: b = a;

J*****n
发帖数: 4859
3

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.

【在 P********e 的大作中提到】
: yes.
P********e
发帖数: 2610
4
你用java就没这问题了
c++的话,不咬用pointer, 用object
struct yourstruct yesterday, today;

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;

t****t
发帖数: 6806
5
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;

S****z
发帖数: 666
6
会,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
发帖数: 10158
7
No

【在 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
发帖数: 10158
8
苏坑总好

【在 S****z 的大作中提到】
: 会,3个new一个delete?这样的好事哪里找?
: 请在return之前把另外两个delete补上

a****l
发帖数: 8211
9
就不准人家搞个循环分三次delete掉?

【在 S****z 的大作中提到】
: 会,3个new一个delete?这样的好事哪里找?
: 请在return之前把另外两个delete补上

J*****n
发帖数: 4859
10
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
发帖数: 6806
11
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
发帖数: 3557
12
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
发帖数: 5298
13
这个是最基本的C++吧,C++ FAQ, C++ FAQ Lite, thinking in C++都有讲

【在 t****t 的大作中提到】
: objects in struct are properly destroyed when struct is destroyed.
:
: container.
: we

J*****n
发帖数: 4859
14

sorry,我昏了头了。你说的是对的。我当时定义的时候,曾经考虑过在vector里面放
shared pt。后来脑袋就昏昏沉沉的,也没有多想。
谢谢。

【在 t****t 的大作中提到】
: objects in struct are properly destroyed when struct is destroyed.
:
: container.
: we

1 (共1页)
进入Programming版参与讨论
相关主题
my wet was deleted?请教一个系统设计问题
旧硬盘如何用?问个 ctor/copy ctor的问题
申请usanews版版主 (转载)is pthread_mutex_destroy() required to call?
问个C++题软件业里最著名的一句话
c++ copy reference 还是deep copy尼玛,这也太容易赚钱了。
有一事我一直就是不明白在并发上haskell可以秒go吗
电话面试题一问 (转载)Google got it wrong. The open-office trend is destroying the workplace.
What is the side effect not to call sem_destroy()?请教一个windows下面的编程问题
相关话题的讨论汇总
话题: struct话题: leakage话题: delete话题: vector话题: memory