d*********1 发帖数: 25 | 1 a few interview questions:
1) is the c++ template parameters decided by the compiling time or running
time?
2) how do you know that a C++ template parameter are decided at the
compiling or running time?
3) what is the initial size of a vector?
4) Can the vector reaches maximum size be changed and how to change it?
5) what kind of tools are you using for debuging multiple threading?
6) how would you know a process is in deadlock? eg in debug mode.
My answers:
1) compiling time?
2) donot know.... |
m********0 发帖数: 2717 | 2 1) compiling
2) designed to be static polymorphism?
3) depends on how you initialize the vector, for default constructor,
vector = vector = vector = vector = 12 on 32
os. vector = 20
4) yes, use vector::reserve(size_type n)
6) deadlock detection is hard. 4 conditions:
Mutual exclusion
Hold and wait
No preemption
Circular wait
don't know how to check it in debug mode
【在 d*********1 的大作中提到】 : a few interview questions: : 1) is the c++ template parameters decided by the compiling time or running : time? : 2) how do you know that a C++ template parameter are decided at the : compiling or running time? : 3) what is the initial size of a vector? : 4) Can the vector reaches maximum size be changed and how to change it? : 5) what kind of tools are you using for debuging multiple threading? : 6) how would you know a process is in deadlock? eg in debug mode. : My answers:
|
p****x 发帖数: 707 | 3 you sure about the initial size? in:
http://www.cplusplus.com/reference/stl/vector/vector/
explicit vector ( const Allocator& = Allocator() );
Default constructor: constructs an empty vector, with no content and a
size of zero.
with a test, after initialization,the size and capacity both are 0, and max_
size is -1. Why -1?
【在 m********0 的大作中提到】 : 1) compiling : 2) designed to be static polymorphism? : 3) depends on how you initialize the vector, for default constructor, : vector = vector = vector = vector = 12 on 32 : os. vector = 20 : 4) yes, use vector::reserve(size_type n) : 6) deadlock detection is hard. 4 conditions: : Mutual exclusion : Hold and wait : No preemption
|
m********0 发帖数: 2717 | 4 I am sure about my result with gnu cpp stl
with g++ compiler.
Tested.
sizeof could not be zero, sizeof(empty clas) = 1;
and for sizeof(vector) I guess the reason is
it only counts three pointers
_M_start, _M_finish, _M_end_of_storage
max_
【在 p****x 的大作中提到】 : you sure about the initial size? in: : http://www.cplusplus.com/reference/stl/vector/vector/ : explicit vector ( const Allocator& = Allocator() ); : Default constructor: constructs an empty vector, with no content and a : size of zero. : with a test, after initialization,the size and capacity both are 0, and max_ : size is -1. Why -1?
|
m********0 发帖数: 2717 | 5 for vector
it has _M_offset for _M_begin and _M_finish
so sizeof (vector) is 20. |
p****x 发帖数: 707 | 6 ok. sizeof of a variable, or initial size of a container?
I guess the interview question is about the later.
【在 m********0 的大作中提到】 : I am sure about my result with gnu cpp stl : with g++ compiler. : Tested. : sizeof could not be zero, sizeof(empty clas) = 1; : and for sizeof(vector) I guess the reason is : it only counts three pointers : _M_start, _M_finish, _M_end_of_storage : : max_
|
m********0 发帖数: 2717 | 7 yes, without definition of "size"
it's confusing.
and sometimes they ask about sizeof a class/variable.
which is the former.
it's too trivial to ask intial number of data in a default vector.
【在 p****x 的大作中提到】 : ok. sizeof of a variable, or initial size of a container? : I guess the interview question is about the later.
|
w*******r 发帖数: 18 | 8 嗯,这三个sizeof只是那三个iterator的大小吧
觉得就算用过c++编过很多程,回答好多面试的这些细节问题,还是挺头疼的啊
【在 m********0 的大作中提到】 : for vector : it has _M_offset for _M_begin and _M_finish : so sizeof (vector) is 20.
|