C + + face question two

Source: Internet
Author: User

Professional Questions

1. The advantages and disadvantages of threading, when to use the best thread, when not the thread?

When to use multithreading technology and when to avoid it is an important subject we need to master. Multi-Threading technology is a double-edged sword, which needs to consider its advantages and disadvantages when using.

Multithreaded processing can run multiple threads at the same time. Because multithreaded applications divide programs into separate tasks, you can significantly improve performance in the following areas: (1) Multithreaded technology makes the program more responsive, because the user interface can be active while doing other work; (2) The processor time can be given to other tasks when the task is not currently being processed, (3) a task that takes up a lot of processing time can give the processor time to other tasks on a regular basis, (4) The task can be stopped at any time, and (5) each task can be prioritized to optimize performance. Whether you need to create multiple threads depends on various factors. Multithreading is best used in the following situations: (1) A time-consuming or heavy-duty processor-intensive task blocks the user interface operation; (2) Each task must wait for an external resource (such as a remote file or Internet connection). In the same way, multithreading also has many drawbacks that need to be fully considered when considering multiple threads. The main disadvantages of multithreading include: (1) waiting for a shared resource causes the program to run slower. These shared resources are primarily exclusive resources, such as printers. (2) Managing threads requires additional CPU overhead. The use of threads can impose an additional burden on the system for context switching. When this burden exceeds a certain level, the characteristics of multithreading are mainly manifested in its shortcomings, such as the use of independent threads to update each element in the array. (3) The deadlock of the thread. That is, long waits or resource contention, as well as deadlocks and other multi-threading symptoms. (4) Read or write to the public variable at the same time. When multiple threads need to write to a public variable, the latter thread tends to modify the data held by the previous thread, thus allowing the parameters of the previous thread to be modified, and, when the read and write operations of the public variable are non-atomic, the uncertainty of the time on different machines, Results in an error in the operation of the data within one thread, resulting in an inexplicable error that the programmer cannot predict.

[Reference address] http://www.cnblogs.com/lmjob/archive/2009/08/10/1542707.html

2. Const char*, char const*, char*const difference

The difference between const char*, Char const*, and char*const is almost always a problem in C + + interview. This knowledge easy to mix the point before is to see, today do Linux write GTK program again appeared a warning, divergent and think of this problem, so turn up and chew it again. In fact, there are just three ways to declare it. Very similar: Bjarne a mnemonic method in his C + + programming language: Read a statement from right to left. char * const CP; (* read into pointer to) CP are a const pointer to charconst char * p; P is a pointer to const CHAR;CHAR const * p; Ibid. because there are no const* operators in C + +, const can only belong to the preceding type. The C + + standard stipulates that the Const keyword is placed before the type or variable name is equivalent. const int n=5; Same as Belowint const M=10 Conclusion: char * const CP: Defines a pointer constant to a character, that is, a const pointer const char* p: Defines a pointer to a character constant char const*          P: equivalent to the const char* P const char * * is a pointer to a pointer pointing to a string constant. char * * is also a pointer to a pointer pointing to a string variable.

[Reference address] http://blog.163.com/pei_hua100/blog/static/805697592009550281616/

C + + face question two

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.