1 About Ram ROM
We know that the RAM type does not have a power-down capability (i.e., a lost power data is all gone), so the app is usually stored in a memory card (Flash) or ROM. RAM is accessed much faster than memory card (Flash) or ROM.
2 when launching an app
To speed up the program execution, the system copies the open app from Flash or ROM to memory (RAM) and executes the code from inside the memory. Another reason is that the CPU cannot read instructions directly from the memory card (flash driver required, etc.).
3 Memory partitions: can be divided into 5 zones
1), stack (stack)-this is generally done by the compiler, will save some local variables, function jump address, site protection and so on
2), heap area (heap)-typically managed by programmers, such as ALLOC application memory
3), Global Zone (static)-the storage of global variables and static variables is placed in a block, initialized global variables and static variables in an area, uninitialized global variables and uninitialized static variables in another area adjacent. -The system is released after the program finishes. Note: The global zone can also be divided into uninitialized global zones:. BSS segment and initialize Global zone: Data segment. Example: int A; uninitialized. int a = 10; initialized.
4), constant area-constant string that's where it's placed.
5), code area-store code, that is, the 2nd app will be copied here.
4 Programming note
When an app launches, the code area, the constant area, and the global size are fixed, so pointers to these areas do not cause a crash error. While the heap and stack areas are constantly changing (heap creation destruction, stack bounce pop-up), so when using a pointer to the memory in these two areas, it is important to note whether the memory has been released, otherwise it will cause program crashes (very common in programming).
As shown: The code area is stored at a low address, and the stack area is stored at a high address.
Memory Partitioning in IOS