动态分配、对齐 IO 缓冲区的 RAII 封装
More...
#include <io_buffer.hpp>
|
| uint8_t * | data_ {nullptr} |
| | 缓冲区数据指针
|
| |
| size_t | size_ {0} |
| | 缓冲区大小
|
| |
动态分配、对齐 IO 缓冲区的 RAII 封装
- Precondition
- 无
- Postcondition
- 缓冲区内存已正确分配并对齐,析构时自动释放
Definition at line 85 of file io_buffer.hpp.
◆ IoBuffer() [1/4]
◆ IoBuffer() [2/4]
构造函数
IoBuffer mock for unit tests — uses malloc/free instead of aligned_alloc which requires the memory subsystem.
- Parameters
-
- Precondition
- size > 0, alignment 必须是 2 的幂
- Postcondition
- 缓冲区内存已正确分配并对齐
- Copyright
- Copyright The SimpleKernel Contributors
Definition at line 12 of file io_buffer.cpp.
12 {
13 assert(size > 0 && "IoBuffer size must be greater than 0");
14 assert((alignment & (alignment - 1)) == 0 &&
15 "IoBuffer alignment must be a power of 2");
16
17 auto* data =
static_cast<uint8_t*
>(
aligned_alloc(alignment, size));
18 assert(data != nullptr && "IoBuffer aligned_alloc failed");
21}
void * aligned_alloc(size_t alignment, size_t size)
◆ ~IoBuffer()
Definition at line 23 of file io_buffer.cpp.
23 {
25 "IoBuffer invariant violated: data_ and size_ must be consistent");
27}
void aligned_free(void *ptr)
◆ IoBuffer() [3/4]
◆ IoBuffer() [4/4]
◆ GetBuffer() [1/2]
| auto IoBuffer::GetBuffer |
( |
| ) |
-> std::span<uint8_t> |
获取缓冲区数据与大小
- Returns
- std::span<uint8_t> 缓冲区数据的可变视图
- Precondition
- None
- Postcondition
- 返回指向缓冲区数据的 span
Definition at line 52 of file io_buffer.cpp.
◆ GetBuffer() [2/2]
| auto IoBuffer::GetBuffer |
( |
| ) |
const -> std::span<const uint8_t> |
获取缓冲区数据与大小 (只读)
- Returns
- std::span<const uint8_t> 缓冲区数据的只读视图
- Precondition
- None
- Postcondition
- 返回指向缓冲区数据的常量 span
Definition at line 48 of file io_buffer.cpp.
◆ IsValid()
| auto IoBuffer::IsValid |
( |
| ) |
const -> bool |
检查缓冲区是否有效
- Returns
- bool 有效则返回 true
- Precondition
- None
- Postcondition
- 返回缓冲区是否已分配且有效的状态
Definition at line 54 of file io_buffer.cpp.
54{
return data_ !=
nullptr; }
◆ operator=() [1/2]
◆ operator=() [2/2]
Definition at line 34 of file io_buffer.cpp.
34 {
35 assert(this != &other && "Self-move assignment is not allowed");
36
37 if (
data_ !=
nullptr) {
39 }
42 other.
data_ =
nullptr;
44
45 return *this;
46}
◆ ToDmaRegion()
◆ data_
| uint8_t* IoBuffer::data_ {nullptr} |
|
private |
◆ kDefaultAlignment
| constexpr size_t IoBuffer::kDefaultAlignment = 4096 |
|
staticconstexpr |
◆ size_
| size_t IoBuffer::size_ {0} |
|
private |
The documentation for this class was generated from the following files: