当前位置:网站首页>[interview arrangement] 0211 game engine server
[interview arrangement] 0211 game engine server
2022-07-07 22:17:00 【r1ch4rd】
List of articles
Self introduction.
Project introduction
C++
Principle and process of realizing polymorphism
1) When the compiler finds a virtual function in the base class , A virtual table is automatically generated for each class containing virtual functions , The table is a one-dimensional array , The virtual table holds the entry address of the virtual function
2) The compiler holds a virtual table pointer in the first four bytes of each object , namely vptr, Points to the virtual table of the class to which the object belongs . At tectonic time , Initialize the virtual pointer according to the type of the object vptr, So that vptr Point to the correct virtual table , So when you call a virtual function , You can find the right function
3) The so-called right time , When a derived class defines an object , The program will automatically call the constructor , Create a virtual table in the constructor and initialize the virtual table . When constructing subclass objects , The constructor of the parent class will be called first , here , The compiler only “ I saw it ” Parent class , And initialize the virtual table pointer for the parent object , Let it point to the virtual table of the parent class ; When calling the constructor of a subclass , Initialize virtual table pointer for subclass object , Let it point to the virtual table of subclasses
4) When the derived class does not override the virtual function of the base class , The virtual table pointer of the derived class points to the virtual table of the base class ; When a derived class rewrites a virtual function of a base class , The virtual table pointer of a derived class points to its own virtual table ; When a derived class has its own virtual function , Add the virtual function address to your own virtual table
So the base class pointer to the derived class at run time , Can be derived according to the virtual function rewriting dynamic call , So as to realize polymorphism .
Can a constructor be a virtual function ? Why? ?
(1) When creating an object, you need to determine the type of object , Virtual functions are dynamically typed at run time . When constructing an object , Because the object has not been created successfully , The compiler cannot know the actual type of the object
(2) Virtual function table pointer is required for calling virtual function vptr, The pointer is stored in the memory space of the object , If the constructor is declared a virtual function , So since the object has not been created , There is no memory space yet , There is no virtual function table vtable The address is used to call the dummy function
(3) The function of a virtual function is to become the member function of the subclass when it is called through the pointer or reference of the parent class . The constructor is called automatically when the object is created , It's impossible to call... Through a parent class or reference , Therefore, it is stipulated that the constructor cannot be a virtual function
C++ Memory space
- Stack
- Store local variables 、 Function parameter
- High efficiency but limited capacity
- Pile up
- Dynamic application for storage , Namely new Allocated memory
- Free storage area
- Between heap 、 Between stacks
- overall situation / Static storage area
- Store global variables and static variables
- Constant storage area
- Placement does not allow modification of constant data
- Code section
- Binary code for storing execution code
- Stack
new and malloc difference
- new Failure to allocate memory is thrown
bad_alloc
abnormal ,malloc Go straight back to null - new Memory allocation is dynamically computed , Allocate in free storage ; and malloc You need to specify the size , Allocate memory on the heap
- new/delete It's the operator , Can overload ;malloc/free yes C Standard library functions , Overloading is not allowed
- new/delete Encapsulates the malloc/free, Except for distribution / Free out of memory , It also calls the constructor / Destructor
- The former returns the pointer type at the time of definition , The latter returns void Type a pointer
- new Failure to allocate memory is thrown
Commonly used STL Introduce the container
map The structure of the underlying implementation
- Red and black trees ,
unordered_map
At the bottom is the hash table
- Red and black trees ,
Characteristics of the red black tree
- First, satisfy the binary sort tree
- All nodes are either black or red
- The root node must be black
- The children of the red node must be black , But the child nodes of the black node can be black
- From roots to NULL The number of black nodes on any path of leaf nodes is the same
Self balancing strategy of red black tree ?
(1) Color change : The nodes of the red black tree change from red to black or from black to red
(2) left-handed : With A node as a fulcrum ( Rotating fulcrum ), Its right child node becomes the parent of the rotation node , The left child of the right child node becomes the right child of the rotating node , The left child node remains unchanged .
(3) Right hand : With A node as a fulcrum ( Rotating fulcrum ), The left child node becomes the parent node of the rotation node , The right child of the left child node becomes the left child of the rotating node , The right child node remains unchanged .
vector Capacity expansion
- Win+VS 1.5 times Linux+GCC 2 times
C++11 New characteristics
Introduction to smart pointer
How to write a template class
How to calculate the number of bytes of memory aligned structure in memory
computer network
- UDP and TCP difference
1、TCP Connection oriented ( If you want to make a call, dial to establish a connection );UDP It's disconnected , That is, you don't need to establish a connection before sending data
2、TCP Provide reliable service . in other words , adopt TCP Connect the transmitted data , No mistakes , No loss , No repetition , And arrive in order ;UDP Do your best to deliver , That is, there is no guarantee of reliable delivery
3、TCP Byte stream oriented , It's actually TCP Think of data as a stream of unstructured bytes ;UDP It's message oriented
UDP no congestion control , Therefore, the network congestion will not reduce the transmission rate of the source host ( Useful for real-time applications , Such as IP Telephone , Real time video conference, etc )
4、 Every one of them TCP Connections can only be point-to-point ;UDP Support one-to-one , One to many , Many to one and many to many interactive communication
5、TCP First cost 20 byte ;UDP The cost of the first part is small , Only 8 Bytes
6、TCP The logical communication channel of is a full duplex reliable channel ,UDP It's an unreliable channel
7、UDP It's message oriented , The sender's UDP For the messages handed in by the application layer , Do not merge , Do not split , Just add a header on it and give it to the network layer below , On the application layer to UDP How many messages , It sends everything , Send one at a time . And docking with the recipient , Directly remove the head after receiving , Give it to the application layer above to complete the task . therefore , It requires the application layer to control the size of the message
TCP Is oriented to a byte stream , It regards the data handed over by the upper application layer as a unstructured byte stream and sends , It can be imagined in the form of running water , The sender TCP Will put the data into “ Reservoir ”( Buffer zone ), Send when you can send , If you can't send it, just wait TCP The size of each message segment will be determined according to the current network congestion state .
- Four kinds of network programming IO Model
(1) Synchronous blocking IO(Blocking IO): Traditional IO Model .
(2) Synchronous nonblocking IO(Non-blocking IO): Created by default socket It's all blocked , Non blocking IO requirement socket Set to NONBLOCK. Pay attention to what's said here NIO Is not Java Of NIO(New IO) library .
(3)IO Multiplexing (IO Multiplexing): Classic Reactor Design patterns , Sometimes called asynchronous blocking IO,Java Medium Selector and Linux Medium epoll It's all this model .
(4) asynchronous IO(Asynchronous IO): Classic Proactor Design patterns , Also known as asynchronous non blocking IO.
- epoll ,poll and select
select At the bottom is a fd_set Data structure of , It's essentially a long An array of types , Each element in the array corresponds to a file descriptor , Check whether any event occurs by polling all file descriptors .
advantage :
1、 Good portability ;
2、 When the number of connections is small and the connections are very active , Good efficiency, too .shortcoming :
1、 The maximum number of file descriptors that can be monitored is 1024( Because the kernel is written ).
2、 Polling traversal is used to check whether there are events , When there are many file descriptors, it is expensive .- poll and select almost , It's just poll There is no maximum number of file descriptions
- epoll Is a more efficient IO The way of multiplexing , The number of file descriptors it can monitor has exceeded 1024 The limitation of ( One hundred thousand ), At the same time, there is no need to check whether there is an event on the file descriptor through polling and traversal , because epoll_wait What is returned is the file descriptor where the event occurred . It is essentially event driven .
operating system
The difference between multiprocessing and multithreading
- There are multiple threads in the same process , Threads share the memory space of the process
- Each process is the basic unit of resource allocation . The process structure consists of the following parts : Code segment 、 stack segment 、 Data segment . Code snippets are static binary code , Multiple programs can be shared . In fact, after the parent process creates the child process , Father 、 In addition to pid Outside , Almost all parts are almost the same .
pthred
andstd::thread
difference- std::thread yes c++ Thread library in standard library , Its significance is that it can cross platform without changing the code
Thread private data
- Private data
- Stack
- state
- register
- Program counter
- Shared data
- Global variables
- Data on heap
- The static variable of the function
- Program code
- Open file
- Private data
gdb debugging
ask
边栏推荐
- Latest Android advanced interview questions summary, Android interview questions and answers
- 双塔模型的最强出装,谷歌又开始玩起“老古董”了?
- What is the reason for the abnormal flow consumption of 4G devices accessing the easygbs platform?
- The maximum number of meetings you can attend [greedy + priority queue]
- How polardb-x does distributed database hotspot analysis
- Overseas agent recommendation
- NVR硬盤錄像機通過國標GB28181協議接入EasyCVR,設備通道信息不顯示是什麼原因?
- 【Azure微服务 Service Fabric 】因证书过期导致Service Fabric集群挂掉(升级无法完成,节点不可用)
- NVR硬盘录像机通过国标GB28181协议接入EasyCVR,设备通道信息不显示是什么原因?
- Reinforcement learning - learning notes 9 | multi step TD target
猜你喜欢
Open source OA development platform: contract management user manual
Display optimization when the resolution of easycvr configuration center video recording plan page is adjusted
Build your own website (18)
How to quickly check whether the opening area ratio of steel mesh conforms to ipc7525
Navicat connect 2002 - can't connect to local MySQL server through socket '/var/lib/mysql/mysql Sock 'solve
Dry goods sharing | devaxpress v22.1 original help document download collection
Reinforcement learning - learning notes 9 | multi step TD target
[azure microservice service fabric] the service fabric cluster hangs up because the certificate expires (the upgrade cannot be completed, and the node is unavailable)
Jerry's test box configuration channel [chapter]
PDF文档签名指南
随机推荐
[open source] Net ORM accessing Firebird database
[azure microservice service fabric] the service fabric cluster hangs up because the certificate expires (the upgrade cannot be completed, and the node is unavailable)
An in-depth understanding of fp/fn/precision/recall
Tupu digital twin coal mining system to create "hard power" of coal mining
npm uninstall和rm直接删除的区别
How to quickly check whether the opening area ratio of steel mesh conforms to ipc7525
Open source OA development platform: contract management user manual
如何实现横版游戏中角色的移动控制
Two kinds of updates lost and Solutions
23. Merge K ascending linked lists -c language
用语雀写文章了,功能真心强大!
OpenGL homework - Hello, triangle
Solve the problem of uni in uni app Request sent a post request without response.
【Azure微服务 Service Fabric 】如何转移Service Fabric集群中的种子节点(Seed Node)
【Azure微服务 Service Fabric 】因证书过期导致Service Fabric集群挂掉(升级无法完成,节点不可用)
Jerry's configuration of TWS cross pairing [article]
Win11游戏模式怎么开启?Win11开启游戏模式的方法
大数据开源项目,一站式全自动化全生命周期运维管家ChengYing(承影)走向何方?
Automatic classification of defective photovoltaic module cells in electronic images
PKPM 2020 software installation package download and installation tutorial