avatar
f*e
1
终于找到工作了,7月份到新的大学报道。
刚刚递交了OPT申请。啥时候可以申请H1B/PERM?多久能够拿到?真想早点拿到PERM,回
国看妈妈就不会很麻烦了。
等你们的回复。谢谢!
avatar
n*d
2
Could any ppl explain the output from vector code below?
avatar
R*r
3
猎头发来的。我没有和这个猎头打过交道。贴在这里攒点RP,呵呵。
avatar
X*r
4
Why don't you also track the constructor and copy constructor? That would
answer your question.
avatar
s*u
5
I believe the employer should be HDR
avatar
n*d
6
Here it is. Why is it copied twice for each push? And the order looks
strange?
Circle
Circle
Circle
push
Circle(&c)
Circle(&c)
Circle(&c)
~Circle
Circle(&c)
Circle(&c)
Circle(&c)
~Circle
~Circle
iterator
Circle::draw
Circle::draw
Circle::draw
done
~Circle
~Circle
~Circle
~Circle
~Circle
~Circle

【在 X****r 的大作中提到】
: Why don't you also track the constructor and copy constructor? That would
: answer your question.

avatar
X*r
7
No, it is not exactly copied twice for each push. Some push are more costly
than others.
More hints:
1. Add tracking statements between the pushes, so you know which push causes
what.
2. Print 'this' in the constructor and both 'this' and the address of the
object being copied from in the copy constructor, so you know which object
is copied to where.
After you have done these,
3. Try adding 'circles.reserve(3);' before the first push_back, see if that
changes anything, and think about why.
Lear

【在 n**d 的大作中提到】
: Here it is. Why is it copied twice for each push? And the order looks
: strange?
: Circle
: Circle
: Circle
: push
: Circle(&c)
: Circle(&c)
: Circle(&c)
: ~Circle

avatar
n*d
8
I may know the answer. vector has to resize the memory for each push and
then move the existing data to new location.

costly
causes
that

【在 X****r 的大作中提到】
: No, it is not exactly copied twice for each push. Some push are more costly
: than others.
: More hints:
: 1. Add tracking statements between the pushes, so you know which push causes
: what.
: 2. Print 'this' in the constructor and both 'this' and the address of the
: object being copied from in the copy constructor, so you know which object
: is copied to where.
: After you have done these,
: 3. Try adding 'circles.reserve(3);' before the first push_back, see if that

avatar
n*d
9
That is. Here is the result.
Circle, this: 0012FF60
Circle, this: 0012FF5C
Circle, this: 0012FF58
push C1
Circle 003707E0 (&c:0012FF60)
push C2
Circle 00370818 (&c:003707E0)
Circle 00370819 (&c:0012FF5C)
~Circle
push C3
Circle 003707E0 (&c:00370818)
Circle 003707E1 (&c:00370819)
Circle 003707E2 (&c:0012FF58)
~Circle
~Circle
iterator
Circle::draw
Circle::draw
Circle::draw
done
~Circle
~Circle
~Circle
~Circle
~Circle
~Circle

【在 n**d 的大作中提到】
: I may know the answer. vector has to resize the memory for each push and
: then move the existing data to new location.
:
: costly
: causes
: that

avatar
l*a
10
我觉得是vector创建了独立的copy,所以当程序退出时候 C1,C2,C3 destructor
called. 但是vector 面也有3个copy.
可以做个测试,你写个constructor。如果同样多出3个constructor 那么就证明是
vector 创建了独立的copy
avatar
d*q
11
when your obj was delivered as an argument without using reference type, the
copy construtor would be invoked to duplicate a object. it is costly
sometimes
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。