官术网_书友最值得收藏!

Summary

Our initial goal in this chapter was to provide an overview of the memory structure of a process in a Unix-like operating system. As we have covered a lot in this chapter, take a minute to read through what we've been through, as you should now feel comfortable in understanding what we have accomplished:

  • We described the dynamic memory structure of a running process as well as the static memory structure of an executable object file.
  • We observed that the static memory layout is located inside the executable object file and it is broken into pieces which are called segments. We found out that the Text, Data, and BSS segments are part of the static memory layout.
  • We saw that the Text segment or Code segment is used to store the machine-level instructions meant to be executed when a new process is spawned out of the current executable object file.
  • We saw that the BSS segment is used to store global variables that are either uninitialized or set to zero.
  • We explained that the Data segment is used to store initialized global variables.
  • We used the size and objdump commands to probe the internals of object files. We can also use object file dumpers like readelf in order to find these segments inside an object file.
  • We probed the dynamic memory layout of a process. We saw that all segments are copied from the static memory layout into the dynamic memory of the process. However, there are two new segments in the dynamic memory layout; the Stack segment, and the Heap segment.
  • We explained that the Stack segment is the default memory region used for allocations.
  • We learned that the local variables are always allocated on top of the Stack region.
  • We also observed that the secret behind the function calls lies within the Stack segment and the way it works.
  • We saw that we have to use a specific API, or a set of functions, in order to allocate and deallocate Heap memory regions. This API is provided by the C standard library.
  • We discussed memory leakage and how it can happen regarding Heap memory regions.

The next chapter is about the Stack and Heap segments specifically. It will use the topics we have covered within this chapter, and it will add more to those foundations. More examples will be given, and new probing tools will be introduced; this will complete our discussion regarding memory management in C.

主站蜘蛛池模板: 惠来县| 贵定县| 凉城县| 祁门县| 福州市| 邳州市| 宝山区| 镇宁| 西乌| 哈巴河县| 曲沃县| 通河县| 龙泉市| 卢龙县| 正镶白旗| 尚志市| 乌拉特中旗| 阳信县| 宜宾市| 巴彦淖尔市| 永昌县| 新巴尔虎右旗| 股票| 永城市| 西藏| 广州市| 奉贤区| 新余市| 怀集县| 云南省| 马龙县| 台中市| 清河县| 三江| 温泉县| 汤阴县| 贺兰县| 含山县| 渭源县| 杭州市| 阜南县|