1. placement new
normal new
- allocates memory
- constructs an object in allocated memory
placement new
- seperate above two things
- we can pass a pre-allocated memory and construct an object in the passed memory
new
allocates memory in heap, whereas placementnew
can be done at known address
2. virtual function
- cannot be
static
- used to achieve runtime polymorphism
- there is virtual destructor but there is no virtual constructor
how does the compiler perform runtime resolution?
vtable
: a table of function pointers, maintained per classvptr
: a pointer tovtable
, maintained per object instance
3. inline function
- the compiler places a copy of
inline
function at each point where it is called - function call overhead does not occur 不会产生函数调用开销
- 只有当编译器知道对象的确切类型时虚调函数才能被内联
4. smart pointer
- Java和C#的Garbage Collection Mechanisms
- a smart pointer is a wrapper class over a pointer with an operator like
*
and->
overloaded
5. b-tree, b+ tree
- the main idea of using B-Trees is to reduce the number of disk accesses
- most of the tree operations require
O(h)
disk accesses where h is the height of the tree - B-tree is a fat tree, the height of B-Trees is kept low by putting maximum possible keys in a B-Tree node
- B+ tree: all keys are at leaf nodes
6. udp and tcp
tcp
- the communicating devices should establish a connection before transmitting data and should close the connection after transmitting the data
- guarantees the delivery of data
- flow control and acknowledgment of data
- packets arrive in order
- slower
udp
- there is no overhead for opening a connection, maintaining a connection, and terminating a connection
- no guarantees the delivery of data
- only checksum
- no sequencing of data
- faster