s*****g 发帖数: 5159 | |
t****t 发帖数: 6806 | 2 i guess you were a java user
in c++ you don't have to initialize v by "v=vector();", or do anything
to release it.
you also don't have to write myClass a=myClass(); just write myClass a; is
enough.
【在 s*****g 的大作中提到】 : Say I have a class
|
O*******d 发帖数: 20343 | |
t****t 发帖数: 6806 | 4 may i ask why is that?
【在 O*******d 的大作中提到】 : vector.push_back的效率很低。
|
O*******d 发帖数: 20343 | |
t****t 发帖数: 6806 | 6 that has nothing to do with low efficiency of vector::push_back(), no?
【在 O*******d 的大作中提到】 : Vector or Deque? Vector的缺点需要Deque来弥补。 : http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1069897449&id=1073086407
|
O*******d 发帖数: 20343 | 7 Vector内部是一块连续的内存。 当capacity用完后,就要把全部数据转到新的更大的
连续内存上。
【在 t****t 的大作中提到】 : that has nothing to do with low efficiency of vector::push_back(), no?
|
p***o 发帖数: 1252 | 8 1 You can reserve() if you know the final size.
2 Even w/o reserve, the amortized cost of push_back is still O(1).
【在 O*******d 的大作中提到】 : Vector内部是一块连续的内存。 当capacity用完后,就要把全部数据转到新的更大的 : 连续内存上。
|
d****p 发帖数: 685 | 9 Among all STL containers, vector is the fastest if number of elements is
less than a modest number, say 100.
【在 O*******d 的大作中提到】 : vector.push_back的效率很低。
|