C++面经

1. placement new

normal new

  1. allocates memory
  2. constructs an object in allocated memory

placement new

  1. seperate above two things
  2. we can pass a pre-allocated memory and construct an object in the passed memory
  3. new allocates memory in heap, whereas placement new can be done at known address

2. virtual function

  1. cannot be static
  2. used to achieve runtime polymorphism
  3. there is virtual destructor but there is no virtual constructor

how does the compiler perform runtime resolution?

  1. vtable: a table of function pointers, maintained per class
  2. vptr: a pointer to vtable, maintained per object instance

3. inline function

  1. the compiler places a copy of inline function at each point where it is called
  2. function call overhead does not occur 不会产生函数调用开销
  3. 只有当编译器知道对象的确切类型时虚调函数才能被内联

4. smart pointer

  1. Java和C#的Garbage Collection Mechanisms
  2. a smart pointer is a wrapper class over a pointer with an operator like * and -> overloaded

5. b-tree, b+ tree

  1. the main idea of using B-Trees is to reduce the number of disk accesses
  2. most of the tree operations require O(h) disk accesses where h is the height of the tree
  3. B-tree is a fat tree, the height of B-Trees is kept low by putting maximum possible keys in a B-Tree node
  4. B+ tree: all keys are at leaf nodes

6. udp and tcp

tcp

  1. the communicating devices should establish a connection before transmitting data and should close the connection after transmitting the data
  2. guarantees the delivery of data
  3. flow control and acknowledgment of data
  4. packets arrive in order
  5. slower

udp

  1. there is no overhead for opening a connection, maintaining a connection, and terminating a connection
  2. no guarantees the delivery of data
  3. only checksum
  4. no sequencing of data
  5. faster
  • 25
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值