SmartOS/Message/WeakStore.h

29 lines
739 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef __WeakStore_H__
#define __WeakStore_H__
#include "Kernel\Sys.h"
// 弱存储。
// 采用全局变量或者堆分配的变量在系统启动时会被清空。
// 弱存储在main函数内栈分配位于栈的最后部分不会因为重启而被清空
class WeakStore
{
public:
cstring Magic; // 幻数。用于唯一标识
uint MagicLength;
ByteArray Data; // 数据
// 初始化
WeakStore(cstring magic = nullptr, byte* ptr = nullptr, uint len = 0);
// 检查并确保初始化,返回原来是否已初始化
bool Check();
void Init();
// 重载索引运算符[],定位到数据部分的索引。
byte operator[](int i) const;
byte& operator[](int i);
};
#endif