pub rec FixedState;
固定缓冲区 bump 分配器状态
buffer:调用者提供的后备缓冲区 capacity:buf 的容量(以字节为单位) offset:到目前为止消耗的字节数(包含对齐填充)
pub fun make(a: *A.Allocator, state: *FixedState, buf: *u8, cap: usize) O.Option[*u8];
在调用者提供的缓冲区之上初始化一个固定缓冲区 Allocator
缓冲区和状态必须比 Allocator 活得更久。内存在 buf 中分配直至耗尽,此后分配将会失败而不是增长。
a:要初始化的 Allocator state:要初始化的 FixedState(必须比 Allocator 活得更久) buf:分配器在其内部进行 bump 的后备缓冲区 cap:buf 的容量(以字节为单位) ret:成功时为 none,或返回错误字符串
pub fun reset(state: *FixedState);
通过倒回到缓冲区起点来一次性回收所有分配
state:要重置的 FixedState
pub fun remaining(state: *FixedState) usize;
缓冲区中剩余的未使用容量
state:要查询的 FixedState ret:分配失败前剩余的字节数(在任何对齐填充之前)