- The difference between UIView and CALayer
- 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