1. The difference between arrays and linked lists
  • Storage units are allocated when they are defined. The number of elements is fixed, and the memory space is high
  • The linked list addresses are discontinuous, slow in search, and efficient in operation. Storage units are dynamically applied for during program execution and can be dynamically added or deleted as required
  1. IOS memory partition situation, five regions
  • The stack areaStackAfter the advancedFILOMultiple threads do not share contiguous memory addresses. They are allocated from high to low, without fragmentation. The stack is a data structure provided by the machine system, and the computer provides support for the stack at the bottom: Special registers are allocated to store the address of the stack, and special instructions are executed to push and unload the stack, which determines the high efficiency of the stack
  • The heap areaHeapDistribution is like a linked list, first in, first outFIFOGenerally need to manually allocate and release heap memory multithreading share discontinuous memory address, from low to high allocation, easy to produce fragmentation space is large, running speed is slow, efficiency is not as stack computer base does not support the heap, the heap is thereC/C++Libraries provide, and fragmentation causes the heap to be less efficient than the stack
  • Global area Global variables and static variables are stored together, initialized global variables and static variables in the same area.data sectionUninitialized global variables and uninitialized static variables are in another adjacent areaThe BSSThe program is released by the system after completion
  • The constant area is where the constant string is placed and released by the system after the program ends
  • The code area holds the binary code of the function body

  • When an app starts, the size of the code area, constant area, and global area are fixed, so Pointers to these areas do not generate crash errors. The heap area and stack area are constantly changing (heap creation and destruction, stack in and out), so when using a pointer to this area of memory, be careful whether the memory has been freed, otherwise it will cause program crash (i.e., the wild pointer error).
  1. Hash table A Hash table (also known as a Hash table) is a data structure that accesses a storage location in memory based on the Key. That is, it accesses records by computing a function on key values that maps the data for the desired query to a location in the table, which speeds up lookups. This mapping function is called a hash function, and the array of records is called a hash table. Generally speaking, the Key is converted to an integer number by a fixed algorithm function (hash function), and then the number is mod by the length of the array. The remainder result is used as the subscript of the array, and the value is stored in the array space with the subscript of the number. When a hash table is used to query data, the hash function is used to convert the key to the corresponding array index and locate the index in the array space to obtain the value. In this way, the array positioning performance is fully utilized to locate data

  2. Where are the Hash tables used in iOS

Attached: my blog address