Why using __attribute__ (section) for some memory allocation?

試著忘記壹切 提交于 2019-12-25 04:43:20

问题


I have foo[NUMBYTES] __attribute__((section(".bar")));

Why using this attribute .bar section? Because foo[] provides already some memory space. Is this for easy memory management?


回答1:


For bare metal code that run without an operating system, the section attribute ,__attribute__((section(".bar"))), is often used to:

  • Place symbols (data or functions) in a special memory space, such as RAM, FLASH or EEPROMs built into microcontrollers.
  • Place symbols at a special address, e.g. placing the interrupt vector table at the start of FLASH for ARM Cortex-M processors.
  • Group related symbols continuously, e.g. the Linux kernel groups initialization code that is only needed at boot together (see init section in linux/init.h) so it can free them later to save RAM.

Search your linker script for references to the named section (.bar) and you could probably make a good guess for its use.



来源:https://stackoverflow.com/questions/27679669/why-using-attribute-section-for-some-memory-allocation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!