2018 iOS interview questions finishing

  • The difference between UIView and CALayer

1. The biggest difference between UIView and CALayer is that UIView can respond to user events, while CALayer cannot. UIView focuses on the management of the displayed content, and CALayer focuses on the drawing of the content.
2. UIView and CALayer are interdependent. UIView relies on the content provided by CALayer, and CALayer relies on the container provided by UIView to display the drawn content. In the final analysis, CALayer is the foundation of all this. If there is no CALayer, UIView itself will not exist. UIView is a special CALayer implementation that adds the ability to respond to events.
3. UIView comes from CALayer, which is higher than CALayer and is the high-level implementation and encapsulation of CALayer. All features of UIView come from CALayer support.
  • Introduce the huge area of ​​memory?

1. The stack area (stack) is automatically allocated and released by the compiler to store the parameter values ​​of the function, local variables, etc. The stack is a system data structure, and the corresponding process/thread is unique. It is fast and efficient, but the disadvantage is that it is limited and the data is inflexible (first in, last out)

2. The heap area is allocated and released by the programmer. In ARC mode, if the program is not released at the end of the program, it will be reclaimed by the operating system.

Advantages: flexible and convenient, data adaptability is extensive, and efficiency is reduced.

3. The global area (static area) (static) global variables and static variables are stored together, initialized global variables and static variables are stored in one area, and uninitialized global variables and static variables are stored in another adjacent block area, which is released by the system after the program ends.

4. The constant area stores constant strings, which are released by the system at the end of the program.

5. The program code area stores the binary code of the function.


  • The principle of multithreading

At the same time, the CPU can only process 1 thread, and only 1 thread is working (executing) multi-threaded concurrent (simultaneous) execution. In fact, the CPU quickly schedules (switches) between multiple threads. If the CPU schedules threads enough time Fast, it creates the illusion of multi-threaded concurrent execution: what happens if there are too many threads?

The CPU will be scheduled among N multi-threads, the CPU will be exhausted, and a large amount of CPU resources will be consumed. The frequency of each thread being scheduled for execution will be reduced (the execution efficiency of the thread will be reduced)

Advantages of Multithreading

Can appropriately improve the execution efficiency of the program Can appropriately improve the resource utilization ( CPU , memory utilization)

Disadvantages of Multithreading

Opening a thread requires a certain amount of memory space (by default, the main thread occupies 1M , and the child thread occupies 512KB ). If a large number of threads are opened, it will occupy a large amount of memory space and reduce the performance of the program.

The more threads, the greater the CPU overhead on scheduling threads, and the programming is more complicated: such as communication between threads, data sharing among multiple threads




Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325389256&siteId=291194637