为什么使用__attribute__(部分)进行一些内存分配? [英] Why using __attribute__ (section) for some memory allocation?
本文介绍了为什么使用__attribute__(部分)进行一些内存分配?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有foo[NUMBYTES] __attribute__((section(".bar")));
为什么使用此属性.bar部分?因为foo []已经提供了一些内存空间.这是为了简化内存管理吗?
解决方案
对于在没有操作系统的情况下运行的裸机代码,section属性__attribute__((section(".bar")))
通常用于:>
- 将符号(数据或函数)放置在特殊的存储空间中,例如微控制器内置的RAM,FLASH或EEPROM.
- 将符号放在特殊地址,例如对于ARM Cortex-M处理器,将中断向量表放在FLASH的开头.
- 连续对相关符号进行分组,例如Linux内核将仅在引导时一起使用的初始化代码分组(请参见
Why using this attribute .bar section? Because foo[] provides already some memory space. Is this for easy memory management?
解决方案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.这篇关于为什么使用__attribute__(部分)进行一些内存分配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文