官方文档翻译-ESP32-Heap Memory Allocation
2018-03-14 11:10
796 查看
堆内存分配
概述
The ESP32 has multiple types of RAM. Internally, there’s IRAM, DRAM as well as RAM that can be used as both. It’s also possible to connect external SPI RAM to the ESP32 - external RAM can be integrated into the ESP32’s memory map using the flash cache.ESP32有多种类型的RAM.在内部,有IRAM,DRAM以及可用作前两者的RAM.也可以将外部SPI RAM连接到ESP32 - 使用闪存缓存可将外部RAM集成到ESP32的存储器映射中.
For most purposes, the standard libc
malloc()and
free()functions can be used for heap allocation without any issues.
对于大多数用途而言,标准的libc
malloc()和
free()函数可以用于堆分配而不会有任何问题.
However, in order to fully make use of all of the memory types and their characteristics, esp-idf also has a capabilities-based heap memory allocator. If you want to have memory with certain properties (for example, DMA-capable memory, or executable memory), you can create an OR-mask of the required capabilities and pass that to
heap_caps_malloc(). For instance, the standard
malloc()implementation internally allocates memory via
heap_caps_malloc(size, MALLOC_CAP_8BIT)in order to get data memory that is byte-addressable.
但是,为了充分利用所有内存类型及其特性,esp-idf还具有基于功能的堆内存分配器.如果您想拥有某些属性的内存(例如,支持DMA的内存或可执行内存),则可以创建所需功能的OR掩码并将其传递给
heap_caps_malloc().例如,标准库的
malloc()在内部的实现是通过
heap_caps_malloc(size, MALLOC_CAP_8BIT)实现获取字节可寻址(byte-addressable)的内存的.
Because malloc uses this allocation system as well, memory allocated using
heap_caps_malloc()can be freed by calling the standard
free()function.
因为malloc也使用这个分配系统,所以用
heap_caps_malloc()分配的内存可以通过调用标准
free()函数来释放.
The “soc” component contains a list of memory regions for the chip, along with the type of each memory (aka its tag) and the associated capabilities for that memory type. On startup, a separate heap is initialised for each contiguous memory region. The capabilitie
94ac
s-based allocator chooses the best heap for each allocation, based on the requested capabilities.
“soc”组件包含芯片的存储器区域列表,以及每个存储器的类型(也就是其标签)以及该存储器类型的关联功能.在启动时,为每个连续的内存区域初始化一个单独的堆.根据基于功能的分配器的请求能力为每个分配选择最佳的堆.
特殊用途
DMA存储器
Use theMALLOC_CAP_DMAflag to allocate memory which is suitable for use with hardware DMA engines (for example SPI and I2S). This capability flag excludes any external PSRAM.
使用
MALLOC_CAP_DMA标志分配适用于硬件DMA控制器(例如SPI和I2S)的内存.此功能标志不包括任何外部PSRAM.
32位可访问内存
If a certain memory structure is only addressed in 32-bit units, for example an array of ints or pointers, it can be useful to allocate it with theMALLOC_CAP_32BITflag. This also allows the allocator to give out IRAM memory; something which it can’t do for a normal malloc() call. This can help to use all the available memory in the ESP32.
如果某个存储器结构仅以32位为单位寻址,例如一个整数或指针数组,则可以使用
MALLOC_CAP_32BIT标志来分配它.这也允许分配器给一些不能使用malloc()的地方分配IRAM内存.这可以帮助使用ESP32中的所有可用内存.
Memory allocated with
MALLOC_CAP_32BITcan only be accessed via 32-bit reads and writes, any other type of access will generate a fatal LoadStoreError exception.
分配有
MALLOC_CAP_32BIT的内存只能通过32位读写访问,任何其他类型的访问都将生成致命的LoadStoreError异常.
API参考 - 堆分配
头文件
heap/include/esp_heap_caps.h本文翻译自:https://esp-idf.readthedocs.io/en/latest/api-reference/system/mem_alloc.html
翻译水平有限,如有错误欢迎指正
相关文章推荐
- 官方文档翻译-ESP32-Wear Levelling APIs
- 官方文档翻译-esp32-uart
- Managing Bitmap Memory管理bitmap内存(Android官方文档翻译——四)
- [iOS]Advanced Memory Management Programming Guide 高级内存管理编程指南(官方文档翻译)
- 官方文档翻译-ESP32-NVS
- 官方文档翻译-ESP32-SPI Flash
- 【翻译】Emmet(Zen Coding)官方文档 之六 自定义 Emmet
- Android Web App官方文档翻译第四章:调试
- YEOMAN官方文档非官方翻译~创造自己的Generator(一)
- spark mlib官方文档学习和翻译笔记(1)
- Flume官方文档翻译之(十三)
- cocos2dx 关于lua 绑定的环境配置官方文档翻译与 将自定义c++方法绑定到lua的的方法
- 对iOS资源包中的图片进行优化(官方文档翻译)(UI设计层面)
- angular4 JavaScript内存溢出问题 (FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory)
- Sencha Touch 2 官方文档翻译之 Using Models(使用数据模型)
- 如何配置OpenGL ES的上下文(OpenGL ES2.0官方文档翻译)
- Android 调试桥官方文档翻译(adb)
- Swift语言官方文档翻译(3)-The Basics
- Aircrack-ng官方文档翻译[中英对照]---Airmon-ng
- ABP官方文档翻译 3.6 工作单元