Netease mutual spicy entertainment me

static role:

1. The first and most important one: Hide

When we compile multiple files at the same time, not all of the prefix plus static global variables and functions have global visibility. If the addition of static, it will be hidden from other source files. For example, in a previously defined and msg plus static, main.c not see them. Using this feature you can define variables with the same name and function of the same name in different files, without worrying about naming conflicts. Static functions and variables can be used as a prefix, for the function in terms of the role of static in hiding only

2.static second role is to keep the contents of the variable persistence

The third role 3.static is initialized to 0 by default

Virtual functions, how to achieve specific

https://blog.csdn.net/weixin_40237626/article/details/82313339

 

The difference between pointers and references:

Memory allocation: Pointer is an entity needs to allocate memory space. Alias reference only variable does not need to allocate memory space.
Initialization: reference must be initialized when defined , and can not be changed. When defining the pointer need not be initialized , and variable space points.
Use level: multiple levels of pointers but not multi-level references, cited only one.
Increment operator: pointer and increment operator cited the results are not the same. (A pointer to the next space, when the reference variable reference value plus 1)
using sizeof: reference magnitude obtained is pointed variable (object), and the pointer obtained sizeof is the size of the pointer itself.
Direct and indirect access: reference to access a variable is accessed directly, while accessing a pointer variable is accessed indirectly.
Wild pointer: Before using pointer best type checking, to prevent stray pointers;
parameter transfer: as a parameter, the substance is passed pass the pointer value , the value passed is the address of a pointer ; mass transfer address referenced essence, transfer It is the address of a variable .

What new can free

Not, new correspondence can not delete the wrong person.
malloc / free, new / delete necessary paired.
malloc and free is c ++, c language standard library function, new, delete a c ++ operator. They are available with the application of dynamic memory and free memory. For non-intra data type of the object, light malloc / free can not meet the requirements of the dynamic object. To automatically perform the function objects created at the same time, the object to be automatically executed destructor before dying. Since malloc / free library function is not an operator, the compiler is not within the purview of control, can not perform the task constructor and destructor imposed malloc / free . C ++ language and therefore need a complete dynamic memory allocation and initialization of operator new, and delete operator can complete a clean-up work and free up memory. Note that new / delete is not a library function.

The difference between malloc, free and new, delete the

C / C ++ generates executable process

1) preprocessing, generating .ii file
2) Compile, produce assembly file (.s file)
3) The assembler generates object files (.o or .obj file)
4) link, to generate an executable file (.out or .exe file)

The concept of compiler: compile program reads source (character stream), to the lexical analysis and syntax, convert the high level language instruction is a functional equivalent of the assembly code, and then converted into machine language by the assembler, and in accordance with the operating system requirements for the executable file format of links to generate an executable program.
Complete the process of compilation: C source code -> precompiled processing (.c) -> compiler, optimizer (.asm, .s) -> Assembler (.obj, .o, .a) - > link program (.exe executable files, etc.)

1. preprocessor (the Preprocess) 

  Read C source of (# instructions beginning) wherein directive processing and special symbols. It includes four categories: macro definitions , conditional compilation instruction, header files , and special symbols.
  Precompiled program is basically done is the source of "alternative" work. After such alternatives, without generating a macro definition, there is no conditional compilation directives, no special symbols output file. The meaning of this document has not been pretreated with the source files are the same, but the content is different.

2. Compile, optimization phase (Compile)

  After pre-compiled output file obtained, only constant; such as numbers, strings, defined variables, and the C language keywords, such as the main, if, else, for, while, {,}, +, -, *, /and many more.
  Compiler have to do is to have to work through lexical analysis and syntax analysis, to confirm all instructions grammatical after which it was translated into intermediate code representation or equivalent assembly code .

  The optimization process is to compile the system in a relatively abstruse technology. It involves not only a problem with compiler technology itself, but with the machine hardware environment also have a great relationship. Part of the optimization intermediate code optimization. This optimization does not depend on a particular computer. Another optimization is aimed at generating the object code carried out.
  For the former optimized main job is to delete a common expression, the optimization loop (mentioned outer codes, strength weakening, conversion loop control condition, a known amount of merger), replication propagation, and delete unused assignment, and the like.
  The latter type is closely related with the optimization of the machine's hardware configuration, the most important is the value of variables to consider how to take full advantage of the machine's various hardware registers to store, in order to reduce the number of memory accesses. In addition, instructions on how and according to the characteristics (such as pipelining, RISC, CISC, VLIW, etc.) the machine hardware that executes instructions to make some adjustments to the target code is relatively short, the higher the efficiency of the implementation, is also an important research topic.
  Optimized assembler code obtained assembler assembler must be converted into a corresponding machine instructions, before the machine can be performed.

3. The assembly process (Assemble)

  Compilation process actually refers to the translation of assembly language code into machine instructions of target process . For each C language source code translation system to be treated, it will eventually go through this process and the corresponding target file. Machine language code stored in the object file that is equivalent to the source of goals.
  Target file consisting of sections. Typically a target file has at least two segments:
  code segment: The segment included in the main program of instructions. The segment is typically readable and executable, but usually not writable.
  Data section: to use a variety of global variables or static data is mainly stored program. General data segments are readable, writable, executable.

  General .obj files generated on a Win32 platform, which has a PE (Portable Executable, namely Windows executable) file format, it contains binary code, but may not be able to perform. When the compiler to a project where all the .cpp file is compiled in a separated manner, and then by the linker links become a .exe or .dll files.

4. linker (Link)

  Generated by the assembler object file can not be executed immediately, in which there may be many problems unresolved.
  For example, the function of a source file may be referenced in a symbolic (e.g., variable or function calls, etc.) defined in another source file; An application may call functions in a library file, and the like. All of these issues need to be resolved before being treated linking programs.
  The main job of the linker is relevant target file connected to each other, the symbol will soon referenced in a document connected with the symbol defined in another file, so that all these objects become a capable eh operating system installed into a unified whole execution .
  According to the different ways of linking with library functions designated by the developer, the link processing

Can be divided into two types:
  (1) static linked
  in such a way link, code function is copied from the final executable program in which the location of the static link library . In this way the program is being executed code will be loaded into the virtual address space in the process . Static link library is actually a collection of object files , each file containing the code base of one or a group of related functions.
  (2) Dynamic Link
  In this manner, the function code is placed in a target is called dynamic link library file or shared object . At this time, the linker made only under the name of the shared object, and other minor registration information recorded in the final executable program . The executable file is executed, the entire contents of the dynamic link library will be mapped into the virtual address space corresponding processes running. The dynamic linker will find the appropriate function code based on the information recorded in the executable program .
  For function calls the executable file, respectively, using the method of dynamic linking or static linking. Use Dynamic Link enables relatively short final executable file and shared objects to be used when multiple processes can save some memory, because in memory only need to save a copy of this shared object code . But not using dynamic link had to be superior to the use of static links. In some cases the dynamic link may cause some damage to the property.

Multi-process and multi-threading options

https://blog.csdn.net/q_l_s/article/details/52608734

 

 

 1) frequent use threads to create a priority destroyed

2) requires a lot of computing priority use of threads

The so-called large number of calculations, of course, is to consume a lot of CPU, frequent switching, and in this case the thread is the most appropriate.

Game server TCP and UDP choice

https://blog.csdn.net/w00w12l/article/details/45077821

https://www.zhihu.com/question/23356564

TCP features:

In principle, TCP's advantages are:

  • Long connection straightforward
  • Reliable information transmission
  • Packet size is not limited

 

The worst feature is its TCP congestion control. Generally, TCP assumes that when the loss is caused due to network bandwidth is not enough, so this happens, the TCP will reduce the contract rate .

In 3G or WiFi, a packet is lost, and you want that immediately retransmit the packet, however, TCP congestion mechanism was completely the other way to deal with!

And there is no way to bypass this mechanism, because it is the basis of the TCP protocol built. This is why in 3G or WiFi environment, ping values ​​can rise to more than 1,000 milliseconds reasons.

UDP features: 

UDP TCP is relatively simple and difficult.

Take, for example, UDP is a packet-based building, which means you are completely subvert the concept in TCP in some respects. UDP only a socket for communication, unlike the need to establish a TCP socket connection for each client. These are very nice place UDP.

However, in most cases you need is just some of the concepts connected fills some of the basic functions of order packets, and so-called connection reliability. Unfortunately, these features are not UDP provides a simple way for you, and you can get free but had to use TCP.

Use local TCP failed:

Reliable UDP is delayed, but because it is a communications protocol established on the basis of UDP, it is possible to reduce the number of ways the delay, unlike TCP, all things must rely on TCP protocol itself can not be change .

World of Warcraft and other games is how to deal with latency problems?

Some similar attack action and special effects can release skills can not return to the server if the server does not receive confirmation of direct execution, such as frozen to show the effect of skills before data on the client side to do it.

The client immediately start computing without waiting for the server to confirm a typical delay of hidden technology.

This also means that we in the end is to use TCP or UDP depends on our ability to hide latency.

TCP at what time failure

TCP uses a game to be able to deal with unexpected delays (Solitaire client was typical delay of one second sudden, the player will not produce anything to complain) or have a good way to alleviate the delay problem.

If you are running a game you can not use any mitigation measures to delay it? Player vs. player action game usually fall into this category, but it also is not limited to action games.

A common operation is that you quickly move your character through a full fog of war map of the world, but once you've explored, the fog will be open.

In order to ensure that the rules of the game, preventing players from cheating, the server can only display information in the vicinity of the player's current location. This means that unlike World of Warcraft, players can not get in without a response from the server, make a complete action. Fog of war probe must rely on open pass over the response from the server.

When packet loss occurs, due to the congestion control server's response rises from 100-150 to 1000-2000 ms ms

There is no way to bypass this setting TCP to avoid this problem.

We replaced the TCP code, with a reliable UDP customized to achieve, to produce a large amount of packet loss delay dropped to just only 50 milliseconds, even more than the situation before TCP packet loss is not a round trip delay of even smaller. Of course, this may be based on UDP, so we have complete control over the reliability of fishes force.

Reliable UDP nothing like TCP, go to achieve a special congestion control. In fact, this is also your biggest reason to use a reliable UDP instead of TCP, to avoid congestion control of TCP.

Baseline

So in the end it is UDP or TCP?

  • If by initiating intermittent stateless client inquiries , and occasionally delay occurs can be tolerated , then use the HTTP / HTTPS it.
  • If the client and server can be independently contract, but the occasional delay can be tolerated (for example: online card game, like many MMO games ), then use the TCP long connection bar.
  • If the client and server can be independently contract, but can not tolerate delay (for example: Most of the multiplayer action games , some of MMO games), then use the UDP it.

Guess you like

Origin www.cnblogs.com/lxy-xf/p/11517873.html