mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-09 07:06:47 +00:00
doc: 内存分配指南
This commit is contained in:
parent
b0474540d4
commit
5c9e03236d
@ -20,6 +20,7 @@
|
|||||||
kernel/boot/index
|
kernel/boot/index
|
||||||
kernel/core_api/index
|
kernel/core_api/index
|
||||||
kernel/process_management/index
|
kernel/process_management/index
|
||||||
|
kernel/memory_management/index
|
||||||
kernel/filesystem/index
|
kernel/filesystem/index
|
||||||
kernel/debug/index
|
kernel/debug/index
|
||||||
kernel/cpu_arch/index
|
kernel/cpu_arch/index
|
||||||
|
15
docs/kernel/core_api/allocate-memory.md
Normal file
15
docs/kernel/core_api/allocate-memory.md
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
# 内存分配指南
|
||||||
|
|
||||||
|
DragonOS提供了一些用于内存分配的api。您可以使用*kmalloc*来分配小的内存块,也可以使用*alloc_pages*分配连续的2MB大小的内存页面。
|
||||||
|
|
||||||
|
## 选择合适的内存分配器
|
||||||
|
|
||||||
|
在内核中,最直接、最简单的分配内存的方式就是,使用`kmalloc()`函数进行分配。并且,出于安全起见,在得到内存块后,我们强烈建议您使用`memset()`函数将该内存区域清零。
|
||||||
|
|
||||||
|
您可以通过`kmalloc()`函数分配得到32bytes到1MBytes之间的内存对象。并且,这些内存对象具有以下的性质:
|
||||||
|
|
||||||
|
- 内存起始地址及大小按照2次幂对齐。(比如,申请的是80bytes的内存空间,那么内存对象大小为128bytes且内存地址按照128bytes对齐)
|
||||||
|
|
||||||
|
对于需要大量连续内存的分配,可以使用`alloc_pages()`向页面分配器申请连续的内存页。
|
||||||
|
|
||||||
|
当内存空间不再被使用时,那么必须释放他们。若您使用的是`kmalloc()`分配的内存,那么您需要使用`kfree()`释放它。若是使用`alloc_pages()`分配的内存,则需要使用`free_pages()`来释放它们。
|
@ -1,3 +1,4 @@
|
|||||||
|
====================================
|
||||||
核心API文档
|
核心API文档
|
||||||
====================================
|
====================================
|
||||||
|
|
||||||
@ -8,3 +9,15 @@
|
|||||||
:caption: 内核实用函数库
|
:caption: 内核实用函数库
|
||||||
|
|
||||||
kernel_api
|
kernel_api
|
||||||
|
|
||||||
|
内存管理
|
||||||
|
===================
|
||||||
|
|
||||||
|
这里快速讲解了如何在DragonOS中分配、使用内存。以便您能快速的了解这个模块。
|
||||||
|
|
||||||
|
详细的内存管理模块的文档请参见::ref:`memory_management_module`
|
||||||
|
|
||||||
|
.. toctree::
|
||||||
|
:maxdepth: 1
|
||||||
|
|
||||||
|
allocate-memory
|
7
docs/kernel/memory_management/index.rst
Normal file
7
docs/kernel/memory_management/index.rst
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
.. _memory_management_module:
|
||||||
|
|
||||||
|
====================================
|
||||||
|
内存管理模块
|
||||||
|
====================================
|
||||||
|
|
||||||
|
[内容待完善]
|
Loading…
x
Reference in New Issue
Block a user