Interviewer: talk about the difference between A and B

The internet

Difference between TCP and UDP

  1. UDP: connectionless unreliable datagram oriented. Using UDP datagram-oriented data transmission scheme, there is no mechanism to ensure reliable transmission, packet loss is not processed. The application layer to the transport layer of how large block of data, the original model as the transport layer transmission block, thus UDP packets needs to be operated at sub-application layer. UDP advantages are: transmission speed, real-time communication scenarios applicable to relatively strong for less demanding data reliability.
  2. TCP: need to go through three-way handshake to establish a connection, TCP confirmation response mechanisms, serial number and confirmation number, retransmission timeout can ensure reliable transmission, for TCP data stream, meaning, no length limit TCP, send and receive data and flexible, but TCP may occur stick package issue.

UDPsendto how to ensure that the peer received?
UDP protocol itself does not have such a function, if you want to achieve guaranteed UDP termination message being transmitted, acknowledgment mechanism may be implemented in an application layer and a UDP retransmission timeout mechanism.

The difference http2 and http1

  1. HTTP2 based on the binary parsing, HTTP1.x based on text parsing, formatting of the text with more, given the robustness of the scene there will be a lot, but http2 unity in binary parsing, convenient and good robustness
  2. Multiplexing, i.e. Connection Sharing, i.e. each request is used as a connection sharing mechanism. A request corresponds to a id, there may be a plurality of such connection request, each request may be connected to random mixed together, then the receiver may be attributed to their different request service ends according to a request which the request ID.
  3. header header compression, each holding a cache communicating parties Fields header parts, i.e. the header transmission to avoid duplication, has reduced transmission of the header size.
  4. Server push, it simply is server side can advance to request sends a plurality of data, such as client requests a resource a, server-side will be a, b, c are sent to the client. If the client requests the next time b, c can be read directly from the cache, do not initiate the request.

The difference http1.0 and http1.1

  1. Caching, in HTTP1.0 header is mainly used in the If-Modified-Since, Expires determination of cache do the standard, then the HTTP1.1 introduces more cache control strategy e.g. Entity tag, If-Unmodified-Since, If-Match, If-None-Match, and more choice of head control cache caching policy.
  2. Bandwidth optimization and use of network connections, the transmission resource portion HTTP1.0 not support, then the HTTP1.1 range request header header field is introduced, which allows only a certain portion of the requested resource, i.e., the return code is 206 (Partial Content).
  3. Management of error notification, a new 24 in HTTP1.1 in response error status code, such as 409 (Conflict) represents the current state of the resource request and resource conflicts; 410 (Gone) represents a resource on the server is permanently nature delete.
  4. Host header processing that each server to bind a unique IP address in HTTP1.0, therefore, the request URL in the message did not get through the host name (hostname). HTTP1.1 request and response messages should support Host header field.
  5. Long connection, HTTP 1.1 support long connector (PersistentConnection) and request pipeline (Pipelining) process, in a TCP connection may transmit a plurality of HTTP requests and responses, and close the connection establishment reducing consumption and delay in the HTTP1.1 enabled by default connection: keep-alive, to some extent make up for the shortcomings HTTP1.0 each request to create a connection.

The difference between http and https

  1. HTTPS protocol requires the CA to request a certificate, the certificate is generally free little need to pay.
  2. HTTP protocol runs on top of TCP, all the contents are transmitted in clear text, HTTPS runs over SSL / TLS, SSL / TLS runs over TCP, the contents of all transmissions are encrypted.
  3. Using HTTP and HTTPS connection is completely different, with the port are not the same, the former is 80, which is 443.
  4. HTTPS can effectively prevent hijacking operators to solve a big problem of anti-hijacking

The difference between GET and POST

  1. GET request parameters in the URL, POST request body in place.
  2. GET request can only be url encoded, POST request support multiple encoding.
  3. GET request parameters passed in the URL is the length restricted, but no POST.
  4. GET more secure than POST, because direct exposure parameters in the URL, so you can not transfer sensitive information.
  5. GET only made once a TCP connection, POST sends two TCP connections. For the GET request, the browser will http header and data sent together, the server response 200 (return data); for the POST, the browser transmits the first header, the server response 100 continue, the browser then transmits data, in response to the server 200 ok (return data). Not all browsers will send two packets, Firefox is sent only once during POST.

The difference between select and epoll

  1. Descriptors quantity: select bitmapped can monitor descriptor has an upper limit, epoll file descriptor is no limit to the number
  2. Lightweight Data Copy: select each call, requires manual collection set fd, each select call set fd need to copy from user mode to kernel mode, fd simultaneously select all require each traverse passed in the call to the kernel . epoll requires a kernel mode to user mode, kernel mode to a copy of the user state.
  3. Interface easy to use: select while adding fd monitor set, still have to use a data structure array select saved into a centralized monitoring fd. epoll file descriptor does not need to set up each cycle of concern.
  4. Event callback mechanism: epoll underlying the use of red-black tree mount epoll event object, and all events will be added to the device (NIC) in the driver epoll callback establish relations, that is, when an event occurs in response to calls this callback function . This callback method called ep_poll_callback in the kernel, it will happen in the event added to the rdlist doubly linked list. When you call epoll_wait check for the event, only you need to check the event ready to eventpoll object rdlist doubly linked list. If rdlist not empty, put the replication events that occur to user mode, and returns the number of events to user. this operation time complexity is O (1).
  5. Expanding knowledge: adding a descriptor to fd_set bitmap, this is the descriptor corresponding to 1 bit position. select using polling determination, if the event is ready within the timeout period, select returns immediately, select returns the number of descriptors. Ready descriptors in such fd_set bitmap, the bitmap is not ready, select is removed, traversing the bitmap, there is also described the icon bitmap descriptor is ready.
  6. Unlike the use of three select bits to represent the three fdset FIG manner, poll a pointer pollfd implementation.

The difference between the level trigger and edge-triggered

  1. epoll defaults LT (level) level epoll_wait trigger event is detected ready, may not be processed immediately, or only part of the process, epoll_wait immediately return a second call epoll_wait time, epoll_wait back, trigger events, and then data processing. Until the data buffers are finished processing, epoll_wait will not return immediately.
  2. ET (Edge) edge-triggered, once the event is ready, it must be dealt with immediately, if the data is not completely processed, the second call epoll_wait, epoll_wait not return. That edge-triggered data processing only once chance, edge-triggered read only supports non-blocking.

operating system

The difference between processes and threads

  1. Address space: between threads in the same process of sharing this process's address space, and the process is a separate address space.
  2. Resources have: threads within the same process share this process resources such as memory, I / O, cpu, open files, signals, etc. (thread also have their own unique data stack, signal mask character, context data, errno), but the process of resources between independent
  3. After a process crashes, it will not have an impact on other processes in protected mode, but a collapse of the entire process threads are dead. So multi-process multi-threaded robust than others.
  4. When switching process, resource consumption, high efficiency. So when it comes to frequent switching, better use threads within a process. Similarly, if requested at the same time and have to share the concurrent operation of certain variables can only be used with the thread can not process
  5. Execution: each individual process inlet path running a sequence program execution sequence and the inlet. But the thread can not execute independently, it must exist according to the application, providing multiple execution threads controlled by the application.
  6. A thread is the basic unit of processor scheduling process is the basic unit of resource allocation and management of resources.
  7. Both can execute concurrently.

When to use multi-process, when to use multithreading?
High resource management and protection requirements, does not limit the costs and efficiency, the use of multiple processes.
High efficiency requirements, frequent switching, time required resource protection and management is not very high, use multiple threads.

The difference between static and dynamic libraries

  1. Static library is replicated at the link stage of the proceedings to the executable program, each program call the static library static library has a copy of the code.
  2. DLL is not copied during the link stage into the program, but the program is loaded at runtime dynamically by the system into memory for program calls. The advantage of using dynamic library is only loaded once dynamic library system, different programs can get a copy of the same dynamic library in memory, thus saving a lot of memory.

The difference between stack and heap

  • Static memory allocation from the region: it is automatically allocated and released by the compiler, that is a good memory has been allocated in the program compile time, this memory during the entire run of the program are present, the entire program runs until the end to be released such as global variables and static variables.
  1. Stack and heap allocation of resources are all dynamically allocated, by alloca function implementation.
  2. Allocated on the stack: it is also automatically allocated and freed by the compiler , that is, when executing a function, the function of the storage unit can create a local variable on the stack, these memory cells will be automatically released at the end of the function execution. Note that the stack memory allocation instruction processor built in centralized operation, its operating efficiency is generally high, but the limited amount of memory allocated.
  3. Dispensing from the heap: also called dynamic memory allocation, it is done by the application programmer and manually released. If the memory space is allocated on the heap, and it must promptly release it, otherwise memory leaks and other errors in the program will lead to the emergence of running.
  4. Frequent allocation and deallocation (malloc / free) heap of different sizes will inevitably lead to discontinuity of memory space, resulting in a large number of fragments, resulting in reduced efficiency of the procedure; and in terms of the stack, it will not have this problem.
  5. Heap mechanism is quite complicated. For example, in order to allocate a heap memory, you should know that the operating system has a list of free memory address is recorded, when the system receives the application process, will traverse the linked list, find the first space is greater than the application heap space node, and remove the node from the linked list of free nodes, and the node allocated to the program space. For most systems, it will be recorded in the memory address space of the first piece of the size of this allocation, so that the code in the delete statement to release this memory space correctly. In addition, due to the size of the size of the heap node found is not necessarily exactly equal to the application, the system will automatically that part of the excess back into the free list. Obviously, the efficiency of the heap than stack allocation is much lower.

C++

The difference between struct and class

Different default permissions inheritance, class inheritance is private inheritance by default, and the default is public struct inheritance.

The difference between references and pointers

  1. A pointer is a variable, the variable is stored contents of the address pointer variable. Reference is an alias variable.
  2. In the definition of reference must be initialized when the pointer is no such requirement, the pointer may also point to NULL, not referenced.
  3. A reference to the entity reference in the initialization, no longer referenced by other entities, and a pointer can point to any type of entity with at any time.
  4. sizeof reference variable physical size = sizeof reference, sizeof pointer size = 4 (32-bit system) or 8 (64-bit system).
  5. Reference safer than pointers, i.e., plus references cited from entity 1 increases, i.e. pointer is incremented and a pointer offset rearwardly type size.

The difference between vector and list of

  1. vector continuous storage, random access support index.
  2. Moving vector copy insertions and deletions may be present in a data block, the time complexity is O (n).
  3. vector compatibilizer may result in copying a data block to move at great cost.
  4. There is also the problem of wasted space vector, vector multiplier receiving a 2 (Linux system capacity of 1.5 multiplication). The reserve functions can be modified vector space, causing unnecessary copy space Capacity expansion brings.
  5. Doubly linked list list can only be accessed through a pointer, does not support random access memory space is not continuous. The advantage is more efficient than the efficiency of insertion and deletion vector.

The difference between the combination and inheritance

  1. public inheritance follow "is a" principle, are inherited.
  2. private and protected inheritance follow "has a" principle, are combined.
  3. In the case where a combination of inheritance and can be used to select combinations. Development should follow the "high cohesion and low coupling" principle.

The difference between new and malloc

  1. new = object constructor + operator new (malloc)
  2. Object destructor delete = + operator delete (free)
  3. new type [size], is the bottom layer by calling operator new disposable open space required, if the custom type defines a destructor, it will open up more operator new four-byte memory size.

The difference between the map and unordered_map

  1. and are based on Key_Value unordered_map map memory structure, can be queried by the unique key value, index can be used [] access.
  2. (Balanced binary tree on the significance of a non-strict) map the underlying red and black tree implementation, internal self-built map a red-black tree, so all of the data within the map are ordered, and map query, insert, delete operation time complexity is O (logN). In use, map to define the key operator <.
  3. The bottom is an anti-redundant unordered_map hash table (in addition to I stay). unordered_map not sorted according to the size of the key, when the storage element is determined according to whether or not the same hash key value, i.e. unordered_map inner elements are unordered. The need to define hash_value unordered_map key function and overload operator ==. The biggest advantage hash table, is to greatly reduce the consumption of data storage and lookup time, the time complexity is O (1); at the cost of only consume more memory.

Guess you like

Origin blog.csdn.net/Vickers_xiaowei/article/details/92805031